问题
We use the following method to add a connection to our OData service in VSTO Excel Add-In. Now we are planning to rewrite the add-ins using Office JS.
What is the similar approach in Office JS Excel Add-In to load data from the OData service?
string connectionString = "DATAFEED;Data Source=http://localhost:8443/OData/ODataService.svc/Products?$filter=Company_Code eq 'TY';Namespaces to Include=*;Max Received Message Size=4398046511104;Integrated Security=Basic;User ID=testuser;Password=123;Persist Security Info=false;Base Url=http://localhost:8443/OData/ODataService.svc/Products?$filter=Company_Code eq 'TY'";
Globals.ThisAddIn.Application.ActiveWorkbook.Connections.Add2(currentWorksheetId, "", connectionString, selectedTables, XlCmdType.xlCmdTableCollection, true, false);
I found an API to get the connections, but I can't seem to find an API to add a new connection:
await Excel.run(async (context) =>
{
let c = context.workbook.dataConnections;
if (c != null)
{
c.refreshAll();
}
await context.sync();
});
Cross posted here.
来源:https://stackoverflow.com/questions/62388829/how-to-add-a-new-connection-using-office-js-excel-add-in-to-retrieve-and-show-da