C++を使用してOData接続情報を取得する方法
Contents
[
Hide
]
OData接続情報を取得
開発者がExcelファイルからOData情報を抽出する必要がある場合があります。 Aspose.Cellsは、Excelファイルに存在するDataMashup情報を返す Workbook.GetDataMashup() プロパティを提供します。この情報は DataMashup クラスによって表されます。 DataMashup クラスは GetPowerQueryFormulas() プロパティを提供し、これは PowerQueryFormulaCollection コレクションを返します。 PowerQueryFormulaCollection から PowerQueryFormula と PowerQueryFormulaItem にアクセスできます。
次のコードスニペットは、これらのクラスを使用してOData情報を取得する方法を示しています。
以下のコードスニペットで使用されるソースファイルは参照用に添付されています。
サンプルコード
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Create workbook
Workbook workbook(srcDir + u"ODataSample.xlsx");
// Get PowerQueryFormulaCollection from DataMashup
PowerQueryFormulaCollection PQFcoll = workbook.GetDataMashup().GetPowerQueryFormulas();
// Iterate through each PowerQueryFormula in the collection
for (int i = 0; i < PQFcoll.GetCount(); ++i)
{
PowerQueryFormula PQF = PQFcoll.Get(i);
std::cout << "Connection Name: " << PQF.GetName().ToUtf8() << std::endl;
// Get PowerQueryFormulaItemCollection from PowerQueryFormula
PowerQueryFormulaItemCollection PQFIcoll = PQF.GetPowerQueryFormulaItems();
// Iterate through each PowerQueryFormulaItem in the collection
for (int j = 0; j < PQFIcoll.GetCount(); ++j)
{
PowerQueryFormulaItem PQFI = PQFIcoll.Get(j);
std::cout << "Name: " << PQFI.GetName().ToUtf8() << std::endl;
std::cout << "Value: " << PQFI.GetValue().ToUtf8() << std::endl;
}
}
Aspose::Cells::Cleanup();
return 0;
}
コンソール出力
Connection Name: Orders
Name: Source
Value: OData.Feed("https://services.odata.org/V3/Northwind/Northwind.svc/", null, [Implementation="2.0"])
Name: Orders_table
Value: Source{[Name="Orders",Signature="table"]}[Data]