Aspoce.cell offset function

Hi,

I am new to Aspose. I am trying to read an excel file using Aspose in C#. I want to use offset function as used in excel. Any pointers like sample code regarding the same would be helpful.

Thanks,

Aneetha.

Hi Aneetha,

Thanks for considering Aspose.

I write the following code for you in (WinForms C#) which refers how to implement formulas using Aspose.Cells API:

Workbook workbook = new Workbook();

workbook.Open(@"d:\templatebook.xls");

Worksheet sheet = workbook.Worksheets[0];

sheet.Cells["A1"].PutValue(380.2);

sheet.Cells["A2"].Formula = "=POWER(A1,2)";

workbook.CalculateFormula();

Double xSquare = sheet.Cells["A2"].DoubleValue;

MessageBox.Show(xSquare.ToString());

sheet.Cells["F5"].PutValue(34);

sheet.Cells["D3"].Formula = "=OFFSET(C3,2,3,1,1)";

workbook.CalculateFormula();

MessageBox.Show(sheet.Cells["D3"].StringValue);

workbook.Save(@"d:\testformula.xls");

Note: Workbook.CalculateFormula() method is only used if you want to calculate the results of the formulas and obtain the results at runtime, otherwise you may skip it for excel.

If you have further queries, feel free to contact us any time.

Regards

Amjad Sahi

Aspose Nanjing Team

Hi Amjad,

Thanks for the prompt reply. I want to convert the following code:

.Cells(n, 2).Offset(0, i + 1).Value

i.e to actually read the value of cell based on an offset from another cell. I don't want to set the offset as a formula to a cell.

Can you please help me with this.

Thanks

Aneetha.

It's easy.

Workbook wb = new Workbook();

Cells cells = wb.Worksheet[0].Cells;

//Set offset to cell B2

Cell cell = cells["B2"];

for(int i = 0; i < 10; i ++)

{

for(int j = 0; j < 10; j ++)

{

object data = cells[cell.Row + i, cell.Column + j].Value;

.......

}

}