Crea e manipola la tabella di Excel
Possibili Scenari di Utilizzo
Aspose.Cells consente di creare e manipolare nuovi o esistenti oggetti elenco o tabelle. È possibile utilizzare vari metodi dell’oggetto elenco o tabella ad es. stile della riga di intestazione, righe delle colonne, tipo di stile, mostra subtotal, ecc. e lavorare anche con singole colonne della tabella e impostare il loro nome e la funzione di calcolo dei totali che potrebbe essere Min, Max, Count, Average, Sum, ecc.
Crea e manipola la tabella di Excel
Il seguente codice di esempio carica il file excel di esempio e quindi crea un oggetto elenco o una tabella in un intervallo A1:H10, quindi utilizza i suoi vari metodi e imposta mostra subtotal. Quindi imposta le funzioni di totale della terza, quarta e quinta colonne a Min, Max e Count rispettivamente e scrive il file excel di output. Lo screenshot seguente mostra l’effetto del codice di esempio sul file excel di esempio dopo l’esecuzione.
Codice di Esempio
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C | |
Aspose::Cells::Startup(); | |
//Source directory path | |
U16String dirPath(u"..\\Data\\TechnicalArticles\\"); | |
//Output directory path | |
U16String outPath(u"..\\Data\\Output\\"); | |
//Path of input excel file | |
U16String sampleCreateAndManipulateExcelTable = dirPath + u"sampleCreateAndManipulateExcelTable.xlsx"; | |
//Path of output excel file | |
U16String outputCreateAndManipulateExcelTable = outPath + u"outputCreateAndManipulateExcelTable.xlsx"; | |
//Load the sample excel file | |
Workbook wb(sampleCreateAndManipulateExcelTable); | |
//Access first worksheet | |
Worksheet ws = wb.GetWorksheets().Get(0); | |
//Add table i.e. list object | |
int idx = ws.GetListObjects().Add(u"A1", u"H10", true); | |
//Access the newly added list object | |
ListObject lo = ws.GetListObjects().Get(idx); | |
//Use its display methods | |
lo.SetShowHeaderRow(true); | |
lo.SetShowTableStyleColumnStripes(true); | |
lo.SetShowTotals(true); | |
//Set its style | |
lo.SetTableStyleType(TableStyleType::TableStyleLight12); | |
//Set total functions of 3rd, 4th and 5th columns | |
lo.GetListColumns().Get(2).SetTotalsCalculation(TotalsCalculation::Min); | |
lo.GetListColumns().Get(3).SetTotalsCalculation(TotalsCalculation::Max); | |
lo.GetListColumns().Get(4).SetTotalsCalculation(TotalsCalculation::Count); | |
//Save the output excel file | |
wb.Save(outputCreateAndManipulateExcelTable); | |
Aspose::Cells::Cleanup(); |