How to add a new connection using Office JS Excel Add-In to retrieve and show data from an OData Service?

和自甴很熟 提交于 2020-06-29 03:47:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!