Guardar tabla dinámica en archivo ODS
Aspose.Cells for Node.js via C++ proporciona la capacidad de guardar la tabla dinámica en archivos ODS. Para ello, simplemente convierte un libro de trabajo con una tabla dinámica existente o crea una nueva y guarda el archivo en formato ODS. Asegúrate de llamar a PivotTable.calculateData antes de guardar para garantizar que la tabla dinámica se renderice en el archivo ODS de salida. El siguiente fragmento de código demuestra cómo guardar la tabla dinámica en un archivo ODS.
Código de Muestra
const AsposeCells = require("aspose.cells.node"); | |
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
var outputDir = RunExamples.Get_OutputDirectory(); | |
// Instantiating a Workbook object | |
var workbook = new AsposeCells.Workbook(); | |
// Obtaining the reference of the newly added worksheet | |
var sheet = workbook.getWorksheets(0).get(0); | |
var cells = sheet.getCells(); | |
// Setting the value to the cells | |
var cell = cells.get("A1");; | |
cell.putValue("Sport"); | |
cell = cells.get("B1"); | |
cell.putValue("Quarter"); | |
cell = cells.get("C1"); | |
cell.putValue("Sales"); | |
cell = cells.get("A2"); | |
cell.putValue("Golf"); | |
cell = cells.get("A3"); | |
cell.putValue("Golf"); | |
cell = cells.get("A4"); | |
cell.putValue("Tennis"); | |
cell = cells.get("A5"); | |
cell.putValue("Tennis"); | |
cell = cells.get("A6"); | |
cell.putValue("Tennis"); | |
cell = cells.get("A7"); | |
cell.putValue("Tennis"); | |
cell = cells.get("A8"); | |
cell.putValue("Golf"); | |
cell = cells.get("B2"); | |
cell.putValue("Qtr3"); | |
cell = cells.get("B3"); | |
cell.putValue("Qtr4"); | |
cell = cells.get("B4"); | |
cell.putValue("Qtr3"); | |
cell = cells.get("B5"); | |
cell.putValue("Qtr4"); | |
cell = cells.get("B6"); | |
cell.putValue("Qtr3"); | |
cell = cells.get("B7"); | |
cell.putValue("Qtr4"); | |
cell = cells.get("B8"); | |
cell.putValue("Qtr3"); | |
cell = cells.get("C2"); | |
cell.putValue(1500) | |
cell = cells.get("C3"); | |
cell.putValue(2000) | |
cell = cells.get("C4"); | |
cell.putValue(600) | |
cell = cells.get("C5"); | |
cell.putValue(1500) | |
cell = cells.get("C6"); | |
cell.putValue(4070) | |
cell = cells.get("C7"); | |
cell.putValue(5000) | |
cell = cells.get("C8"); | |
cell.putValue(6430) | |
var pivotTables = sheet.getPivotTables(); | |
// Adding a PivotTable to the worksheet | |
var index = pivotTables.add("=A1:C8", "E3", "PivotTable2"); | |
// Accessing the instance of the newly added PivotTable | |
var pivotTable = pivotTables.get(index); | |
// Unshowing grand totals for rows. | |
pivotTable.setRowGrand(false); | |
// Draging the first field to the row area. | |
pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Row, 0); | |
// Draging the second field to the column area. | |
pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Column, 1); | |
// Draging the third field to the data area. | |
pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Data, 2); | |
pivotTable.calculateData(); | |
// Saving the ODS file | |
workbook.save(outputDir + "PivotTableSaveInODS_out.ods"); |
El archivo de salida generado del código anterior está adjunto para su referencia.