简体   繁体   English

是否可以将 XML 或 JSON 数据从 Word 在线文档中的表格作为 HTML 表格导入 Apps Script 网站?

[英]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?

I am building a web app using Apps Script.我正在使用 Apps 脚本构建一个网络应用程序。 In this web app I have a table that needs to be populated from a table in a Word doc in OneDrive.在此 Web 应用程序中,我有一个表,需要从 OneDrive 中 Word 文档中的表填充。 This document is updated regularly, so I would prefer to programmatically update the content of the html table in Apps Script.本文档会定期更新,因此我更愿意以编程方式更新 Apps Script 中 html 表的内容。 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.我已经开始研究从 url 导入 xml,但我不确定我是否走在正确的轨道上。

You need to incorporate the following steps您需要合并以下步骤

  • Read your data into a Google Apps function, eg with OneDriveApp as recommended by Cooper将您的数据读入 Google Apps 功能,例如使用 Cooper 推荐的OneDriveApp
  • Use google.script.run to call the Apps Script function from you html file使用google.script.run从你的html文件中调用 Apps Script 函数
  • Incorporate a Web Polling function that updates your html table with fresh contents in desired intervals结合网络轮询功能,以所需的时间间隔用新鲜内容更新您的 html 表格

Sample:样本:

code.gs代码.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索引.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>
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM