Läs och skriv tabell med datakälla för frågetabell

Läs och skriv tabell med datakälla för frågetabell

Med Aspose.Cells för Python via .NET kan du läsa och skriva en tabell som har en QueryTable som datakälla. Support för denna funktion finns även för XLS-filer. Följande kodexempel visar hur man läser och skriver en sådan tabell genom att först läsa tabellen och sedan modifiera den för att lägga till totalsraden.

from aspose.cells import Workbook
from aspose.cells.tables import TableDataSourceType
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the source directory.
sourceDir = RunExamples.Get_SourceDirectory()
outputDir = RunExamples.Get_OutputDirectory()
# Load workbook object
workbook = Workbook(sourceDir + "SampleTableWithQueryTable.xls")
worksheet = workbook.worksheets[0]
table = worksheet.list_objects[0]
# Check the data source type if it is query table
if table.data_source_type == TableDataSourceType.QUERY_TABLE:
table.show_totals = True
# Save the file
workbook.save(outputDir + "SampleTableWithQueryTable_out.xls")

Käll- och utdataexcelfilerna är bilagda som referens.

Källfil

Resultatfil