【问题标题】:Dynamic spreedsheet ID in html file [closed]html文件中的动态电子表格ID [关闭]
【发布时间】:2020-10-30 16:36:14
【问题描述】:

我正在使用 gs 显示图表,我使用的数据来自同一个电子表格:

function ruptureTraca() {
  var ui = HtmlService.createHtmlOutputFromFile('ChartLine').setWidth(1350).setHeight(550);
  SpreadsheetApp.getUi().showModelessDialog(ui,"Evolution Backlog");
  
}

ChartLine html 文件如下所示:

<!DOCTYPE html>
<html>
  <head>
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
     google.charts.load("current", {packages: ["corechart", "line"]});
     google.charts.setOnLoadCallback(drawChart);
     function drawChart() {
var query = new google.visualization.Query(
          'https://docs.google.com/spreadsheets/d/[spreadSheet_ID]/edit?sheet=for%20Graph&headers=1');
...

我想将电子表格的 id 添加为变量,例如:

var query = new google.visualization.Query(
          'https://docs.google.com/spreadsheets/d/' + id + '/edit?sheet=for%20Graph&headers=1');

为了复制文件和图表功能将能够从新电子表格而不是原始电子表格中获取数据。

【问题讨论】:

标签: javascript html google-apps-script google-visualization


【解决方案1】:

您可以将 id 作为参数添加到 drawChart 函数中...

 function drawChart(id) {
   var query = new google.visualization.Query(
      'https://docs.google.com/spreadsheets/d/' + id + '/edit?sheet=for%20Graph&headers=1');

然后调用尽可能多的 ID...

 google.charts.load("current", {packages: ["corechart", "line"]});
 google.charts.setOnLoadCallback(function () {
   drawChart(id_1);
   drawChart(id_2);
 });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-13
    • 2011-07-21
    • 1970-01-01
    • 2012-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多