Agregar Conexión de Pivote con C++
Contents
[
Hide
]
Escenarios de uso posibles
Si desea asociar filtro y tabla dinámica en Excel, debe hacer clic con el botón derecho en el filtro y seleccionar el elemento “Conexiones de informe…”. En la lista de opciones, puede operar en la casilla de verificación. Del mismo modo, si desea asociar filtro y tabla dinámica usando la API de Aspose.Cells programáticamente, utilice el método Slicer.AddPivotConnection(PivotTable pivot). Asociará el filtro y la tabla dinámica.
Asociar filtro y tabla dinámica
El siguiente código de ejemplo carga el archivo de Excel de ejemplo que contiene un rebanador existente. Accede al Rebanador y luego asocia el Rebanador y la Tabla dinámica. Finalmente, guarda el libro de trabajo como archivo de Excel de salida.
Código de muestra
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Output directory path
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Path of input Excel file
U16String inputFilePath = srcDir + u"add-pivot-connection.xlsx";
// Path of output Excel file
U16String outputFilePath = outDir + u"add-pivot-connection-out.xlsx";
// Create workbook
Workbook workbook(inputFilePath);
// Access first worksheet
WorksheetCollection worksheets = workbook.GetWorksheets();
Worksheet worksheet = worksheets.Get(0);
// Access the first PivotTable inside the PivotTable collection
PivotTableCollection pivotTables = worksheet.GetPivotTables();
PivotTable pivotTable = pivotTables.Get(0);
// Access the first slicer inside the slicer collection
SlicerCollection slicers = worksheet.GetSlicers();
Slicer slicer = slicers.Get(0);
// Add PivotTable connection
slicer.AddPivotConnection(pivotTable);
// Save the workbook
workbook.Save(outputFilePath);
std::cout << "PivotTable connection added successfully!" << std::endl;
Aspose::Cells::Cleanup();
}