如何获取 OData 连接信息
Contents
[
Hide
]
获取 OData 连接信息
在某些情况下,开发人员可能需要从 excel 文件中提取 OData 信息。 Aspose.Cells 提供了工作簿.DataMashup返回 Excel 文件中存在的 DataMashup 信息的属性。此信息由 DataMashup 类表示。 DataMashup 类提供返回 PowerQueryFormulaCollction 集合的 PowerQueryFormulas 属性。从 PowerQueryFormulaCollction,您可以访问 PowerQueryFormula 和 PowerQueryFormulaItem。
以下代码片段演示了如何使用这些类来检索 OData 信息。
附上以下代码片段中使用的源文件供您参考。
示例代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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()); | |
} | |
} |
控制台输出
连接名称:订单
名称:来源
值:OData.Feed(“https://services.odata.org/V3/Northwind/Northwind.svc/", null, [Implementation=“2.0”])
名称:订单表
值:来源{[Name=“Orders”,Signature=“table”]}[Data]