alexa
menu

Document Processing

    Show / Hide Table of Contents

    Interface IRange

    Represents a cell, a row, a column, collection of cells or a 3-D Range.

    Inherited Members
    IParentApplication.Application
    IParentApplication.Parent
    Namespace: Syncfusion.XlsIO
    Assembly: Syncfusion.XlsIO.Base.dll
    Syntax
    public interface IRange : IParentApplication, IEnumerable<IRange>, IEnumerable

    Properties

    Address

    Gets the Range reference in macro language. Read-only.

    Declaration
    string Address { get; }
    Property Value
    Type
    System.String
    Examples

    The following code illustrates how to access Address property of the Range.

    ExcelEngine excelEngine = new ExcelEngine();
    IApplication application = excelEngine.Excel;
    application.DefaultVersion = ExcelVersion.Excel2013;
    IWorkbook workbook = application.Workbooks.Create(1);
    
    IWorksheet sheet = workbook.Worksheets[0];
    string address = sheet.Range[3, 4].Address;
    
    workbook.SaveAs("Address.xlsx");
    workbook.Close();
    excelEngine.Dispose();

    AddressGlobal

    Gets the Range reference along with its sheet name in format "'Sheet1'!$A$1". Read-only.

    Declaration
    string AddressGlobal { get; }
    Property Value
    Type
    System.String
    Examples

    The following code illustrates how to access AddressGlobal property of the Range.

    ExcelEngine excelEngine = new ExcelEngine();
    IApplication application = excelEngine.Excel;
    application.DefaultVersion = ExcelVersion.Excel2013;
    IWorkbook workbook = application.Workbooks.Create(1);
    
    IWorksheet sheet = workbook.Worksheets[2];
    string address = sheet.Range[4, 3].AddressGlobal;
    
    workbook.SaveAs("AddressGlobal.xlsx");
    workbook.Close();
    excelEngine.Dispose();

    AddressLocal

    Gets the Range reference in language of the user. Read-only.

    Declaration
    string AddressLocal { get; }
    Property Value
    Type
    System.String
    Examples

    The following code illustrates how to access AddressLocal property of the Range.

    ExcelEngine excelEngine = new ExcelEngine();
    IApplication application = excelEngine.Excel;
    application.DefaultVersion = ExcelVersion.Excel2013;
    IWorkbook workbook = application.Workbooks.Create(1);
    
    IWorksheet sheet = workbook.Worksheets[0];
    string address = sheet.Range[1, 2].AddressLocal; 
    
    workbook.SaveAs("AddressLocal.xlsx");
    workbook.Close();
    excelEngine.Dispose();

    AddressR1C1

    Gets the Range reference along with sheet name using R1C1-style notation. Read-only.

    Declaration
    string AddressR1C1 { get; }
    Property Value
    Type
    System.String
    Examples

    The following code illustrates how to access AddressR1C1 property of the Range.

    ExcelEngine excelEngine = new ExcelEngine();
    IApplication application = excelEngine.Excel;
    application.DefaultVersion = ExcelVersion.Excel2013;
    IWorkbook workbook = application.Workbooks.Create(1);
    
    IWorksheet sheet = workbook.Worksheets[0];
    string address = sheet.Range[1, 1].AddressR1C1;
    
    workbook.SaveAs("AddressR1C1.xlsx");
    workbook.Close();
    excelEngine.Dispose();

    AddressR1C1Local

    Gets the Range reference using R1C1-style notation. Read-only.

    Declaration
    string AddressR1C1Local { get; }
    Property Value
    Type
    System.String
    Examples

    The following code illustrates how to access AddressR1C1Local property of the Range.

    ExcelEngine excelEngine = new ExcelEngine();
    IApplication application = excelEngine.Excel;
    application.DefaultVersion = ExcelVersion.Excel2013;
    IWorkbook workbook = application.Workbooks.Create(1);
    
    IWorksheet sheet = workbook.Worksheets[0];
    string address = sheet.Range[1, 1].AddressR1C1Local;
    
    workbook.SaveAs("AddressR1C1Local.xlsx");
    workbook.Close();
    excelEngine.Dispose();

    Boolean

    Gets or sets boolean value in the Range.

    Declaration
    bool Boolean { get; set; }
    Property Value
    Type
    System.Boolean
    Examples

    The following code illustrates how to set and access Boolean property of the Range.

    ExcelEngine excelEngine = new ExcelEngine();
    IApplication application = excelEngine.Excel;
    application.DefaultVersion = ExcelVersion.Excel2013;
    IWorkbook workbook = application.Workbooks.Create(1);
    
    IWorksheet sheet = workbook.Worksheets[0];
    sheet.Range[2, 4].Boolean = true;
    bool boolean = sheet.Range[2, 4].Boolean;
    
    workbook.SaveAs("Boolean.xlsx");
    workbook.Close();
    excelEngine.Dispose();

    Borders

    Gets a IBorders collection that represents the borders of a style in the Range. Read-only.

    Declaration
    IBorders Borders { get; }
    Property Value
    Type
    IBorders
    Remarks

    Borders including a Range defined as part of a conditional format will be returned.

    Examples

    The following code illustrates how to access Borders property of the Range.

            using (ExcelEngine excelEngine = new ExcelEngine())
            {
                //Create worksheet
                IApplication application = excelEngine.Excel;
                application.DefaultVersion = ExcelVersion.Excel2013;
                IWorkbook workbook = application.Workbooks.Create(1);
                IWorksheet worksheet = workbook.Worksheets[0];
    
                //Set text
                worksheet["C2"].Text = "Sample";
    
                //Set borders
                IBorders borders = worksheet["C2"].Borders;
    
                //Set border color
                borders[ExcelBordersIndex.EdgeTop].Color = ExcelKnownColors.Red;
                borders[ExcelBordersIndex.EdgeBottom].Color = ExcelKnownColors.Blue;
    
                //Set line style
                borders[ExcelBordersIndex.EdgeTop].LineStyle = ExcelLineStyle.Thick;
                borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Thick;
    
                //Save and dispose
                workbook.SaveAs("CellFormats.xlsx");
                workbook.Close();
            }

    BuiltInStyle

    Gets or sets built in style in the Range.

    Declaration
    Nullable<BuiltInStyles> BuiltInStyle { get; set; }
    Property Value
    Type
    System.Nullable<BuiltInStyles>
    Examples

    The following code illustrates how to set BuiltInStyle to a range.

            using (ExcelEngine excelEngine = new ExcelEngine())
            {
                //Create worksheet
                IApplication application = excelEngine.Excel;
                application.DefaultVersion = ExcelVersion.Excel2013;
                IWorkbook workbook = application.Workbooks.Create(1);
                IWorksheet worksheet = workbook.Worksheets[0];
    
                //Set text
                worksheet["C2"].Text = "Sample";
    
                //Set built in style
                worksheet["C2"].BuiltInStyle = BuiltInStyles.Accent3;
    
                //Save and dispose
                workbook.SaveAs("CellFormats.xlsx");
                workbook.Close();
            }

    CalculatedValue

    Gets the calculated value of a formula in the Range. Read-only.

    Declaration
    string CalculatedValue { get; }
    Property Value
    Type
    System.String
    Remarks

    To compute a formula, it is mandatory to enable calculate engine by invoking EnableSheetCalculations method of worksheet object. It is also recommend to disable calculate engine once all formula are computed by invoking DisableSheetCalculations method of worksheet object

    Examples

    Following code illustrates how to access a calculated value.

    ExcelEngine excelEngine = new ExcelEngine();
    IApplication application = excelEngine.Excel;
    application.DefaultVersion = ExcelVersion.Excel2013;
    IWorkbook workbook = application.Workbooks.Open("Sample.xlsx", ExcelOpenType.Automatic);
    IWorksheet sheet = workbook.Worksheets[0];
    
    //Initializes Calculate Engine to perform calculation
    sheet.EnableSheetCalculations();
    
    //Returns the calculated value of a formula using the most current inputs
    string calculatedValue = sheet["C1"].CalculatedValue;
    //Formula calculation is disabled for the sheet.
    sheet.DisableSheetCalculations();  
    
    workbook.SaveAs("Formula.xlsx");
    workbook.Close();
    excelEngine.Dispose();       

    Cells

    Gets a IRange object that represents the cells in the Range. Read-only.

    Declaration
    IRange[] Cells { get; }
    Property Value
    Type
    IRange[]
    Examples

    The following code illustrates how to access Cells property of the Range.

    ExcelEngine excelEngine = new ExcelEngine();
    IApplication application = excelEngine.Excel;
    application.DefaultVersion = ExcelVersion.Excel2013;
    IWorkbook workbook = application.Workbooks.Create(1);
    
    IWorksheet sheet = workbook.Worksheets[0];
    IRange[] cells = sheet["A1:E8"].Cells;
    foreach (IRange Range in cells)
    {
        // Do some manipulations
    }
    
    workbook.SaveAs("Cells.xlsx");
    workbook.Close();
    excelEngine.Dispose();

    CellStyle

    Gets a IStyle object that represents the style of the Range.

    Declaration
    IStyle CellStyle { get; set; }
    Property Value
    Type
    IStyle
    Remarks

    To know more about setting styles refer Set Default Style for row/column.

    Examples

    The following code illustrates how to access IStyle using CellStyle property of the Range.

            using (ExcelEngine excelEngine = new ExcelEngine())
            {
                //Create worksheet
                IApplication application = excelEngine.Excel;
                application.DefaultVersion = ExcelVersion.Excel2013;
                IWorkbook workbook = application.Workbooks.Create(1);
                IWorksheet worksheet = workbook.Worksheets[0];
    
                //Set text
                worksheet["C2"].Text = "Sample";
    
                //Add style
                IStyle style = workbook.Styles.Add("BorderStyle");
    
                //Set color
                style.ColorIndex = ExcelKnownColors.Red;
    
                //Set style
                worksheet["C2"].CellStyle = style;
    
                //Save and dispose
                workbook.SaveAs("CellFormats.xlsx");
                workbook.Close();
            }

    CellStyleName

    Gets name of the IStyle object that represents style of the Range.

    Declaration
    string CellStyleName { get; set; }
    Property Value
    Type