首页 > 解决方案 > html 文件中的动态电子表格 ID

问题描述

我正在使用 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');

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

标签: javascripthtmlgoogle-apps-scriptgoogle-visualization

解决方案


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

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

然后调用尽可能多的次数...

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

推荐阅读