We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to apply formulas on Range like range("A2:Z2").Formula = sum(a-b)

How to apply formulas on Range like range(“A2:Z2”).Formula = sum(a,b)

Hi Narendra,

Thanks for your posting and considering Aspose.Cells.

You can create a Range and then iterate its cells and apply formula. Please see the following code. It applies formula to cells A2:Z2 iteratively.

I have attached the output xlsx file generated by this code for your reference.


Workbook workbook = new Workbook();

Worksheet worksheet = workbook.Worksheets[0];

Range range = worksheet.Cells.CreateRange(“A2:Z2”);

//Iterate all cells in a range and apply formula

for (int r = range.FirstRow; r < range.FirstRow + range.RowCount; r++)


for (int c = range.FirstColumn; c < range.FirstColumn + range.ColumnCount; c++)


Cell cell = worksheet.Cells[r, c];

cell.Formula = “=Sum(A1:B1)”;




Thank you…

How can i get max used rows number from sheet.
owc : OWCSheet.ActiveSheet.UsedRange.Rows.Count


Hi Narendra,

Thanks for your posting and using Aspose.Cells.

You can find the maximum row which contains some data or style using the Worksheet.Cells.MaxRow property. Similarly, if you want to find maximum row that contains some data, then you can use Worksheet.Cells.MaxDataRow property.

These properties also exist for columns. Worksheet.Cells.MaxColumn property will give you a maximum column that may contain some data or style. While Worksheet.Cells.MaxDataColumn will give you a maximum column that contains some data.


Workbook workbook = new Workbook(filePath);

Worksheet worksheet = workbook.Worksheets[0];

Console.WriteLine("Maximum Row: " + worksheet.Cells.MaxRow);

Console.WriteLine("Maximum Data Row: " + worksheet.Cells.MaxDataRow);

Console.WriteLine("Maximum Column: " + worksheet.Cells.MaxColumn);

Console.WriteLine("Maximum Data Column: " + worksheet.Cells.MaxDataColumn);