在新行中输入数据时自动在表或列表对象中传播公式
Contents
[
Hide
]
可能的使用场景
有时,您希望表或列表对象中的公式在输入新数据时自动传播到新行。这是 Microsoft Excel 的默认行为。为了实现与 Aspose.Cells 相同的功能,请使用列表列.公式财产。
在新行中输入数据时自动在表或列表对象中传播公式
以下示例代码创建一个表或列表对象,这样当您输入新数据时,B 列中的公式将自动传播到新行。请检查输出excel文件使用此代码生成。如果您在单元格 A3 中输入任何数字,您将看到,单元格 B2 中的公式会自动传播到单元格 B3。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |