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 for Python via .NET, 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.

from aspose.cells import Workbook
from aspose.cells.tables import TableStyleType
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Create workbook object
book = Workbook()
# Access first worksheet
sheet = book.worksheets[0]
# Add column headings in cell A1 and B1
sheet.cells.get(0, 0).put_value("Column A")
sheet.cells.get(0, 1).put_value("Column B")
# Add list object, set its name and style
listObject = sheet.list_objects[sheet.list_objects.add(0, 0, 1, sheet.cells.max_column, True)]
listObject.table_style_type = TableStyleType.TABLE_STYLE_MEDIUM2
listObject.display_name = "Table"
# Set the formula of second column so that it propagates to new rows automatically while entering data
listObject.list_columns[1].formula = "=[Column A] + 1"
# Save the workbook in xlsx format
book.save(dataDir + "output_out.xlsx")