Hur man får OData anslutningsinformation

Få OData-anslutningsinformation

Det kan finnas fall där utvecklare behöver extrahera OData information från excelfilen. Aspose.Cells tillhandahåller Workbook.DataMashup egenskapen som returnerar DataMashup-informationen som finns i Excel-filen. Denna information representeras av DataMashup-klassen. DataMashup-klassen tillhandahåller egenskapen PowerQueryFormulas som returnerar PowerQueryFormulaCollction-samlingen. Från PowerQueryFormulaCollction kan du få tillgång till PowerQueryFormula och PowerQueryFormulaItem.

Följande kodsnutt visar användningen av dessa klasser för att hämta OData-informationen.

Källfilen som används i den följande kodsnutten bifogas för din referens.

Källfil

Exempelkod

// 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());
}
}

Konsoloutput

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]