C++ でワークシートからピボットテーブルを削除します
Contents
[
Hide
]
Aspose.Cellsでは、ワークシートからピボットテーブルを削除する機能が提供されています。ピボットテーブルオブジェクトやピボットテーブルの位置を使用して削除できます。
次のサンプルコードは、ワークシートから2つのピボットテーブルを削除します。最初に Worksheet.PivotTables.Remove() メソッドを使ってピボットテーブルを削除し、その後 Worksheet.PivotTables.RemoveAt() メソッドを使ってもう一つのピボットテーブルを削除します。
#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"source.xlsx";
// Path of output Excel file
U16String outputFilePath = outDir + u"output_out.xlsx";
// Create workbook object from source Excel file
Workbook workbook(inputFilePath);
// Access the first worksheet
Worksheet worksheet = workbook.GetWorksheets().Get(0);
// Access the first pivot table object
PivotTable pivotTable = worksheet.GetPivotTables().Get(0);
// Remove pivot table using pivot table object
worksheet.GetPivotTables().Remove(pivotTable);
// OR you can remove pivot table using pivot table position by uncommenting below line
// worksheet.GetPivotTables().RemoveAt(0);
// Save the workbook
workbook.Save(outputFilePath);
std::cout << "Pivot table removed successfully!" << std::endl;
Aspose::Cells::Cleanup();
}