Propaga automaticamente la formula nella tabella o nell'oggetto elenco durante l'inserimento dei dati in nuove righe
Contents
[
Hide
]
Possibili scenari di utilizzo
A volte, si desidera che una formula nella tabella o nell’oggetto elenco si propaghi automaticamente a nuove righe durante l’inserimento di nuovi dati. Questo è il comportamento predefinito di Microsoft Excel. Per ottenere la stessa cosa con Aspose.Cells, si prega di utilizzareListColumn.Formulaproprietà.
Propaga automaticamente la formula nella tabella o nell’oggetto elenco durante l’inserimento dei dati in nuove righe
Il seguente codice di esempio crea una tabella o un oggetto elenco in modo tale che la formula nella colonna B si propaghi automaticamente alle nuove righe quando si immettono nuovi dati. Si prega di controllarefile excel di output generato con questo codice. Se inserisci un numero qualsiasi nella cella A3, vedrai che la formula nella cella B2 si propaga automaticamente alla cella B3.
This file contains 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"); |