如何使用 C++ 获取 OData 连接信息
Contents
[
Hide
]
获取OData连接信息
可能会遇到开发者需要从Excel文件中提取OData信息的情况。Aspose.Cells提供了Workbook.GetDataMashup()属性,可以返回Excel文件中的DataMashup信息。该信息由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]