Propagate Formula in Table or List Object automatically while entering data in new rows

Possible Usage Scenarios

Sometimes, you want a formula in your Table or List Object automatically propagates to new rows while entering new data. This is the default behavior of Microsoft Excel. In order to achieve the same thing with Aspose.Cells, please use ListColumn.Formula property.

Propagate Formula in Table or List Object automatically while entering data in new rows

The following sample code creates a Table or List Object in such a way that the formula in column B will automatically propagate to new rows when you will enter new data. Please check the output excel file generated with this code. If you enter any number in cell A3, you will see, the formula in cell B2 automatically propagates to cell B3.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create workbook object
Workbook book = new Workbook();
// Access first worksheet
Worksheet sheet = book.Worksheets[0];
// Add column headings in cell A1 and B1
sheet.Cells[0, 0].PutValue("Column A");
sheet.Cells[0, 1].PutValue("Column B");
// Add list object, set its name and style
ListObject listObject = sheet.ListObjects[sheet.ListObjects.Add(0, 0, 1, sheet.Cells.MaxColumn, true)];
listObject.TableStyleType = TableStyleType.TableStyleMedium2;
listObject.DisplayName = "Table";
// Set the formula of second column so that it propagates to new rows automatically while entering data
listObject.ListColumns[1].Formula = "=[Column A] + 1";
// Save the workbook in xlsx format
book.Save(dataDir + "output_out.xlsx");