SpreadsheetGear
IRange Interface
Members  Example  See Also  Send Feedback
SpreadsheetGear Namespace : IRange Interface

Represents one or more cells, rows, columns, or ranges of cells.

Syntax

Visual Basic (Declaration) 
<DefaultMemberAttribute("Item")>
Public Interface IRange 
C# 
[DefaultMemberAttribute("Item")]
public interface IRange 

Example

C#Copy Code
class Program
{
   
static void Main()
   {
       
// Create a workbook.
       
SpreadsheetGear.IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook();
       
// Get the worksheet and change the name.
       
SpreadsheetGear.IWorksheet worksheet = workbook.Worksheets["Sheet1"];
       worksheet.Name =
"2005 Sales";
       
// Get the worksheet cells reference.
       
SpreadsheetGear.IRange cells = worksheet.Cells;
       
// Add column headers using a string index into the cell range.
       
cells["B1"].Formula = "Jan";
       cells[
"C1"].Formula = "Feb";
       cells[
"D1"].Formula = "Mar";
       
// Add row headers using zero based row and column indexes.
       
cells[1, 0].Formula = "Jennifer";
       cells[2, 0].Formula =
"William";
       cells[3, 0].Formula =
"Kristen";
       
// Add random data using a multiple cell string index.
       
cells["B2:D4"].Formula = "=RAND()*10000";
       
// Center the column headers using multiple cell row and column indexes.
       
cells[0, 1, 0, 3].HorizontalAlignment = SpreadsheetGear.HAlign.Center;
       
// Bold the row and column headers using a string index to multiple ranges.
       
cells["B1:D1,A2:A4"].Font.Bold = true;
       
// Format the data as currency.
       
cells["B2:D4"].NumberFormat = "$#,##0";
       
// Write the workbook.
       
workbook.SaveAs("2005 Sales.xls", SpreadsheetGear.FileFormat.XLS97);
   }
}
    
Visual BasicCopy Code
Class Program
    Shared Sub Main()
        ' Create a workbook.
        Dim workbook As SpreadsheetGear.IWorkbook = SpreadsheetGear.Factory.GetWorkbook()
        ' Get the worksheet and change the name.
        Dim worksheet As SpreadsheetGear.IWorksheet = workbook.Worksheets("Sheet1")
        worksheet.Name = "2005 Sales"
        ' Get the worksheet cells reference.
        Dim cells As SpreadsheetGear.IRange = worksheet.Cells
        ' Add column headers using a string index into the cells range.
        cells("B1").Formula = "Jan"
        cells("C1").Formula = "Feb"
        cells("D1").Formula = "Mar"
        ' Add row headers using zero based row and column indexes.
        cells(1, 0).Formula = "Jennifer"
        cells(2, 0).Formula = "William"
        cells(3, 0).Formula = "Kristen"
        ' Add random data using a multiple cell string index.
        cells("B2:D4").Formula = "=RAND()*10000"
        ' Center the column headers using multiple cell row and column indexes.
        cells(0, 1, 0, 3).HorizontalAlignment = SpreadsheetGear.HAlign.Center
        ' Bold the row and column headers using a string index to multiple ranges.
        cells("B1:D1,A2:A4").Font.Bold = True
        ' Format the data as currency.
        cells("B2:D4").NumberFormat = "$#,##0"
        ' Write the workbook.
        workbook.SaveAs("2005 Sales.xls", SpreadsheetGear.FileFormat.XLS97)
    End Sub 'Main
End Class 'Program

Requirements

Namespace: SpreadsheetGear

Platforms: Windows 2000, Windows XP, Windows Vista, Windows Server 2003 and Windows Server 2008. SpreadsheetGear 2008 requires the Microsoft .NET Framework 2.0 and supports .NET 3.0 and .NET 3.5.

Assembly: SpreadsheetGear (in SpreadsheetGear.dll)

See Also

Copyright © 2003-2009 SpreadsheetGear LLC. All Rights Reserved.Help Powered by Innovasys   
SpreadsheetGear is a registered trademark of SpreadsheetGear LLC.
Microsoft, Microsoft Excel and Visual Studio are trademarks or registered trademarks of Microsoft Corporation.