Forums     Knowledge Base     OfficeWriter Online     
 
 
This documentation is for
OfficeWriter v3.7.1
.NET Platform

View Docs for Another
Version or Platform

Programmer's Reference > ExcelApplication API > Range

The Range Object


A Range object represents a range in a workbook. A range is a collection of areas. An area is a rectangular collection of cells. The areas in a range may be non-adjacent, and a range can include areas in different worksheets.

To create a Range (without a name), call one of the following methods:

  • Workbook.CreateRange(rangeFormula)
  • Worksheet.CreateRange(rangeFormula)
  • Worksheet.CreateRangeOfColumns(firstCol, numCols)
  • Worksheet.CreateRangeOfRows(int firstRow, int numRows)

If a range is named, it will be accessible when the workbook is opened in Microsoft Excel. To create a named range, call one of the following methods:

  • Workbook.CreateNamedRange(rangeFormula, rangeName)
  • Worksheet.CreateNamedRange(firstRow, firstColumn, numRows, numColumns, rangeName)
  • Worksheet.CreateNamedRange(rangeFormula, rangeName)


Examples:

[csharp]
ExcelApplication xla = new ExcelApplication();
Workbook wb = xla.Create();
wb.Worksheets.CreateWorksheet("Sheet2");
Range rng = wb.CreateRange("=Sheet1!A1:A3, Sheet2!A2:C5");
[vbnet]
Dim xla As New ExcelApplication()
Dim wb As Workbook = xla.Create()
wb.Worksheets.CreateWorksheet("Sheet2")
Dim rng As Range = wb.CreateRange("=Sheet1!A1:A3, Sheet2!A2:C5")


Range Properties

Property Type Access Description
AreaCount int read

Returns the number of Areas contained in this Range

Areas Area[] read

Returns an array of the rectangular areas contained in the Range

BorderAround Border read

Sets or returns a Border object that represents a border around the range

FirstCellStyle Style read

Returns the style for the first cell in the range

Item Area read

Returns the Area object at the specified 0-based index



Range Methods

ReturnsSignature and Description
void ApplyStyle ( Style style )

Applies a style to the area

void ClearContent ( )

Clears the content of all cells in the range

void JoinRange ( Range range )

Adds another range to this range

void RemoveConditionalFormat ( )

This method removes any ConditionalFormat objects from the Range.

void SetConditionalFormat ( ConditionalFormat conditionalFormat )

This method copies the specified ConditionaFormat object and associates it with this Range

void SetDataValidation ( DataValidation dataValidation )

Assigns a data validation rule to all cells in the Range

void SetStyle ( Style style )

Sets the style for every cell in this range



Copyright 2006 © SoftArtisans, Inc. All Rights Reserved.