我已经使用相同的工作表代码一段时间了,以查询我的Google电子表格。 (各个站点上的电子表格不同,等等。)由于我不确定这次的原因,我收到了回调错误“ SheetrockError:请求失败”。不知道我在做什么错。

我尝试过搜索堆栈溢出和Sheetrock Github Repo,甚至在那里打开了一个问题,没有响应。

这是我的JS代码:

var mySpreadsheet = 'https://docs.google.com/spreadsheets/d/e/2PACX-1vSkcN_ec394URPCLiZ5R5YD3qTS65Q9oUken30dhFhm_rLVYftuFc9h9DPuWqtrgz1m27zVVVuEOfQE/pubhtml?gid=585428784';
var bandsTemplate = Handlebars.compile($('#bands-template').html());

function loadResults() {
  $('#bands').sheetrock({
    url: mySpreadsheet,
    query: "select A,B,C,D,E,F,G order by A asc",
    rowTemplate: bandsTemplate,
    callback: function(error, options, response) {
      if (!error) {
        $('#bands').tablesorter();
      }
      else {
        console.log(error);
      }
    }
  });
}

loadResults();


这是我的HTML代码:

<div class="table-responsive">
            <table id="bands" class="table tablesorter">
              <thead>
                <tr>
                  <th class="col-xs-1">Song<br>Name <i class="fa fa-sort fa-fw" aria-hidden="true"></i></th>
                  <th>Band <i class="fa fa-sort fa-fw" aria-hidden="true"></i></th>
                  <th>Arranger <i class="fa fa-sort fa-fw" aria-hidden="true"></i></th>
                  <th>Date <i class="fa fa-sort fa-fw" aria-hidden="true"></i></th>
                  <th>YouTube Link <i class="fa fa-sort fa-fw" aria-hidden="true"></i></th>
                  <th>Notes <i class="fa fa-sort fa-fw" aria-hidden="true"></i></th>
                </tr>
              </thead>
              <script id="bands-template" type="text/x-handlebars-template">
                {{#if num}}
                  <tr>
                    <td><a href="{{cellsArray.[7]}}">{{cellsArray.[0]}}</a></td>
                    <td>{{cellsArray.[1]}}</td>
                    <td>{{cellsArray.[2]}}</td>
                    <td>{{cellsArray.[3]}}</td>
                    <td><a href="{{cellsArray.[4]}}">{{cellsArray.[4]}}</a></td>
                    <td>{{cellsArray.[8]}}</td>
                  </tr>
                {{/if}}
              </script>
            </table>
          </div>


我还将代码设置在JS Fiddle link中,以便于预览(已经链接了Sheetrock和jQuery插件)。

我的预期结果是让sheetrock插件使用提供的代码成功调用电子表格。

Safari也出现以下两个错误:

[Error] Failed to load resource: the server responded with a status of 404 () (tq, line 0)
[Error] Refused to execute https://docs.google.com/spreadsheets/d/e/gviz/tq?gid=585428784&tq=select%20A%2CB%2CC%2CD%2CE%2CF%2CG%20order%20by%20A%20asc&tqx=responseHandler:_sheetrock_callback_0 as script because "X-Content-Type: nosniff" was given and its Content-Type is not a script MIME type.

最佳答案

OP的代码足够,只有两个例外:

共享:OP电子表格尚未按照文档要求的形式公开共享。

OP使用发布到Web,但是Sheetrock文档解释了"Click “Share” and set visibility to “Anyone with the link” or “Public on the web.” Make sure you include the #gid=X portion of the URL; it identifies the specific worksheet you want to use.

电子表格链接应如下所示:


  https://docs.google.com/spreadsheets/d/1lJSFqDWzLyiYl4rUOe_mm0NJ6yvtwj8lFIihkuwH4VA/edit#gid=0


数值数据列:Sheetrock.js seems to need at least one column of numerical data.在文档中没有特别提及,但是在未解决的问题中进行了讨论。没有数字列,sheetrock将不会包括所有数据行。

这是我的电子表格的视图:
    javascript - “SheetrockError:请求失败”,但没有更多详细信息-LMLPHP

该jsfiddle仅使用OP列表中的一些条目,但它演示了表的显示以及表排序器的操作。

jsfiddle

08-19 00:18