Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

A1-style references are easy to read, intuitive, and match the default reference style seen in Microsoft Excel.

Example

Code Block
c#
c#

ExcelApplication xla = new ExcelApplication();
Workbook wb = xla.Create();
Worksheet ws = wb.Worksheets[0];
ws.Cells["A3"].Value = "Jan";
ws.Cells["B3"].Value = "Feb";
ws.Cells["C3"].Value = "Mar";
Area a = ws.CreateArea("=A1:G10");

...

Relative R1C1 references enable you to reuse a single formula in multiple rows or columns. The following example copies one formula to three different columns to calculate the sum of those columns.

Code Block
c#
c#

ExcelApplication xla = new ExcelApplication();
Workbook wb = xla.Create();
wb.UseRCFormulaNotation = true;
Worksheet ws = wb.Worksheets[0];
String formulaString = "=SUM(R[-12]C:R[-1]C)";
Cell columnTotal;
for (int i = 0;i < 3; i++)
{
     columnTotal = ws.Cells[13, i + 1];
     columnTotal.Formula = formulaString;
}

...

The following specifies cell A1 by 0-based row and column numbers: The first parameter of the Cell property is the row index, the second is the column index.

Code Block
c#
c#

sheet1.Cells[2, 0].Value = "SoftArtisans OfficeWriter";

Using row and column numbers makes it easy to iterate over cells:for(int iRow = 3; iRow <= 23; iRow++)

Code Block
c#
c#

for(int iCol = 0; iCol <= 2; iCol++)
     sheet1.Cells[iRow, iCol].Value = iRow + iCol;