如何获取OData连接信息

获取OData连接信息

在某些情况下,开发人员可能需要从 Excel 文件中提取 OData 信息。Aspose.Cells 提供了返回 Excel 文件中存在的 DataMashup 信息的 Workbook.DataMashup 属性。这些信息由 DataMashup 类表示。DataMashup 类提供了 PowerQueryFormulas 属性,该属性返回 PowerQueryFormulaCollction 集合。通过 PowerQueryFormulaCollction,您可以访问 PowerQueryFormula 和 PowerQueryFormulaItem。

以下代码片段演示了使用这些类来检索OData信息。

以下代码片段中使用的源文件,请参考附件。

源文件

示例代码

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the directories.
String sourceDir = Utils.Get_SourceDirectory();
Workbook workbook = new Workbook(sourceDir + "ODataSample.xlsx");
PowerQueryFormulaCollction PQFcoll = workbook.getDataMashup().getPowerQueryFormulas();
for (Object obj : PQFcoll)
{
PowerQueryFormula PQF = (PowerQueryFormula)obj;
System.out.println("Connection Name: " + PQF.getName());
PowerQueryFormulaItemCollection PQFIcoll = PQF.getPowerQueryFormulaItems();
for (Object obj2 : PQFIcoll)
{
PowerQueryFormulaItem PQFI = (PowerQueryFormulaItem)obj2;
System.out.println("Name: " + PQFI.getName());
System.out.println("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]