How to get OData Connection Information
Get OData Connection Information
There might be cases where developers need to extract OData information from the excel file. Aspose.Cells provides the Workbook.DataMashup property which returns the DataMashup information present in the Excel file. This information is represented by the DataMashup class. The DataMashup class provides the PowerQueryFormulas property that returns the PowerQueryFormulaCollction collection. From the PowerQueryFormulaCollction, you can get access to PowerQueryFormula and PowerQueryFormulaItem.
The following code snippet demonstrates the use of these classes to retrieve the OData information.
The Source file used in the following code snippet is attached for your reference.
Sample Code
// 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()); | |
} | |
} |
Console Output
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]