Leggere e scrivere la tabella con l'origine dati della tabella delle query

Leggere e scrivere la tabella con l’origine dati della tabella delle query

Con Aspose.Cells, puoi leggere e scrivere una tabella che ha una QueryTable come origine dati. Il supporto per questa funzione esiste anche per i file XLS. Il frammento di codice seguente illustra la lettura e la scrittura di una tabella di questo tipo leggendo prima la tabella e quindi modificandola per aggiungere la riga dei totali.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the output directory.
String sourceDir = Utils.Get_SourceDirectory();
String outputDir = Utils.Get_OutputDirectory();
// Load workbook object
Workbook workbook = new Workbook(sourceDir + "SampleTableWithQueryTable.xls");
Worksheet worksheet = workbook.getWorksheets().get(0);
ListObject table = worksheet.getListObjects().get(0);
// Check the data source type if it is query table
if (table.getDataSourceType() == TableDataSourceType.QUERY_TABLE)
{
table.setShowTotals(true);
}
// Save the file
workbook.save(outputDir + "SampleTableWithQueryTable_out.xls");

I file excel di origine e di output sono allegati per riferimento.

File sorgente

File di uscita