C++を使用してピボットテーブルの外部接続データソースを取得する
Contents
[
Hide
]
ピボットテーブルの外部接続データソースの取得
Aspose.Cellsはピボットテーブルの外部接続データソースを取得する機能を提供します。 このために、APIは PivotTable クラスの GetExternalConnectionDataSource() プロパティを提供します。 GetExternalConnectionDataSource() プロパティは ExternalConnection オブジェクトを返します。 次のコードスニペットは、 PivotTable.GetExternalConnectionDataSource() プロパティを使用してピボットテーブルの外部接続データソースを取得する方法を示しています。
サンプルコード
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
using namespace Aspose::Cells::ExternalConnections;
int main()
{
Aspose::Cells::Startup();
// Source directory
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Load sample file
Workbook workbook(srcDir + u"SamplePivotTableExternalConnection.xlsx");
// Get the first worksheet
Worksheet worksheet = workbook.GetWorksheets().Get(0);
// Get the pivot table
PivotTable pivotTable = worksheet.GetPivotTables().Get(0);
// Print External Connection Details
std::cout << "External Connection Data Source" << std::endl;
// Get the source data connections
Vector<ExternalConnection> connections = pivotTable.GetSourceDataConnections();
// Iterate through each connection and print details
int32_t connectionCount = connections.GetLength();
for (int32_t i = 0; i < connectionCount; ++i)
{
ExternalConnection conn = connections[i];
std::cout << "Name: " << conn.GetName().ToUtf8() << std::endl;
std::cout << "Type: " << static_cast<int>(conn.GetSourceType()) << std::endl;
}
Aspose::Cells::Cleanup();
}
コードスニペットで使用されるソースファイルは、参照用に添付されています。