Come ottenere le informazioni sulla connessione OData con C++
Contents
[
Hide
]
Ottenere informazioni sulla connessione OData
Ci possono essere casi in cui gli sviluppatori devono estrarre informazioni OData dal file Excel. Aspose.Cells fornisce la proprietà Workbook.GetDataMashup() che restituisce le informazioni DataMashup presenti nel file Excel. Queste informazioni sono rappresentate dalla classe DataMashup. La classe DataMashup fornisce la proprietà GetPowerQueryFormulas() che restituisce la collezione PowerQueryFormulaCollection. Da PowerQueryFormulaCollection, puoi accedere a PowerQueryFormula e PowerQueryFormulaItem.
Il seguente frammento di codice dimostra l’uso di queste classi per recuperare le informazioni OData.
Il file di origine utilizzato nello snippet di codice seguente è allegato per il tuo riferimento.
Codice di Esempio
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Create workbook
Workbook workbook(srcDir + u"ODataSample.xlsx");
// Get PowerQueryFormulaCollection from DataMashup
PowerQueryFormulaCollection PQFcoll = workbook.GetDataMashup().GetPowerQueryFormulas();
// Iterate through each PowerQueryFormula in the collection
for (int i = 0; i < PQFcoll.GetCount(); ++i)
{
PowerQueryFormula PQF = PQFcoll.Get(i);
std::cout << "Connection Name: " << PQF.GetName().ToUtf8() << std::endl;
// Get PowerQueryFormulaItemCollection from PowerQueryFormula
PowerQueryFormulaItemCollection PQFIcoll = PQF.GetPowerQueryFormulaItems();
// Iterate through each PowerQueryFormulaItem in the collection
for (int j = 0; j < PQFIcoll.GetCount(); ++j)
{
PowerQueryFormulaItem PQFI = PQFIcoll.Get(j);
std::cout << "Name: " << PQFI.GetName().ToUtf8() << std::endl;
std::cout << "Value: " << PQFI.GetValue().ToUtf8() << std::endl;
}
}
Aspose::Cells::Cleanup();
return 0;
}
Output della console
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]