Propagare la formula in un entità tabella o elenco automaticamente durante l inserimento dei dati in nuove righe

Possibili Scenari di Utilizzo

A volte si desidera che una formula nella propria tabella o oggetto elenco si propaghi automaticamente alle nuove righe durante l’inserimento di nuovi dati. Questo è il comportamento predefinito di Microsoft Excel. Per ottenere lo stesso risultato con Aspose.Cells, utilizzare la proprietà ListColumn.Formula.

Propagare la formula nella tabella o nell’oggetto elenco automaticamente durante l’inserimento dei dati nelle nuove righe

Il seguente codice di esempio crea un’entità tabella o un oggetto elenco in modo che la formula nella colonna B si propaghi automaticamente alle nuove righe quando si inseriscono nuovi dati. Si prega di controllare il file Excel di output generato con questo codice. Se si inserisce un numero in cella A3, si vedrà che la formula nella cella B2 si propaga automaticamente alla cella 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");