如何获取OData连接信息

获取OData连接信息

可能存在需要从Excel文件中提取OData信息的情况。 Aspose.Cells提供Workbook.DataMashup属性,返回Excel文件中存在的DataMashup信息。此信息由DataMashup类表示。DataMashup类提供PowerQueryFormulas属性,返回PowerQueryFormulaCollction集合。从PowerQueryFormulaCollction中,您可以访问PowerQueryFormulaPowerQueryFormulaItem

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

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

源文件

示例代码

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// source directory
string SourceDir = RunExamples.Get_SourceDirectory();
Workbook workbook = new Workbook(SourceDir + "ODataSample.xlsx");
PowerQueryFormulaCollection PQFcoll = workbook.DataMashup.PowerQueryFormulas;
foreach (PowerQueryFormula PQF in PQFcoll)
{
Console.WriteLine("Connection Name: " + PQF.Name);
PowerQueryFormulaItemCollection PQFIcoll = PQF.PowerQueryFormulaItems;
foreach (PowerQueryFormulaItem PQFI in PQFIcoll)
{
Console.WriteLine("Name: " + PQFI.Name);
Console.WriteLine("Value: " + PQFI.Value);
}
}

控制台输出

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]