Is it possible to import XML or JSON data from a table within a Word online document into Apps Script website as an HTML table?

江枫思渺然 提交于 2020-01-30 08:20:29

问题


I am building a web app using Apps Script. In this web app I have a table that needs to be populated from a table in a Word doc in OneDrive. This document is updated regularly, so I would prefer to programmatically update the content of the html table in Apps Script. Is this possible? If so, can anyone give me guidance as to how to accomplish this?

I've started looking into importing xml from a url, but I'm not sure that I'm on the right track.


回答1:


You need to incorporate the following steps

  • Read your data into a Google Apps function, e.g. with OneDriveApp as recommended by Cooper
  • Use google.script.run to call the Apps Script function from you html file
  • Incorporate a Web Polling function that updates your html table with fresh contents in desired intervals

Sample:

code.gs

function doGet(){
  return HtmlService.createHtmlOutputFromFile('index');
}
function getFreshData(){
  //read here your Word Doc data, e.g. with One DriveApp and store it e.g. in an array
  ...
  return myDataArray;
}

index.html

...
<body onload="polling()">
...
  <script>
    function polling(){
      setInterval(myFunction,2000);  //chose how often you want your table
     }
    function myFunction(){
      google.script.run.withSuccessHandler(onSuccess).getFreshData();        
    }
    function onSuccess(myDataArray){
      // Create a html table with the freshly obtained myDataArray from the Word Doc
     ...
    }
  </script>
...


来源:https://stackoverflow.com/questions/59604294/is-it-possible-to-import-xml-or-json-data-from-a-table-within-a-word-online-docu

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