如何通过Node.js和C++获取OData连接信息
Contents
[
Hide
]
获取OData连接信息
在某些情况下,开发者需要从Excel文件中提取OData信息。Aspose.Cells for Node.js via C++提供Workbook.getDataMashup()属性,可返回Excel文件中的DataMashup信息。这些信息由DataMashup类表示。DataMashup类提供DataMashup.getPowerQueryFormulas()属性,返回PowerQueryFormulaCollection集合。通过PowerQueryFormulaCollection,可以访问PowerQueryFormula和PowerQueryFormulaItem。
以下代码片段演示了使用这些类来检索OData信息。
以下代码片段中使用的源文件,请参考附件。
示例代码
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "ODataSample.xlsx");
// Loads the workbook which contains hidden external links
const workbook = new AsposeCells.Workbook(filePath);
const PQFcoll = workbook.getDataMashup().getPowerQueryFormulas();
for (let i = 0; i < PQFcoll.getCount(); i++) {
const PQF = PQFcoll.get(i);
console.log("Connection Name: " + PQF.getName());
const PQFIcoll = PQF.getPowerQueryFormulaItems();
for (let j = 0; j < PQFIcoll.getCount(); j++) {
const PQFI = PQFIcoll.get(j);
console.log("Name: " + PQFI.getName());
console.log("Value: " + PQFI.getValue());
}
}
控制台输出
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]