display the content of a google sheet cell in a web page

自闭症网瘾萝莉.ら 提交于 2019-12-23 02:31:28

问题


I have google sheet with a cell containing html code. I would like to know the best way to show this html in a webpage. I have tried with google spreadsheets API and google visualization API...


回答1:


Using Google Apps Script, this can be as simple as:

function doGet() {
  var spreadsheet = SpreadsheetApp.openById("0Aq4s9w_HxMs7dFVuQ0hDaWl1VVZsQ1RBTVZqM0dHLXc"); // replace with your sheet id
  var html = spreadsheet.getRange("A1").getValue(); // My html is in cell A1
  return HtmlService.createHtmlOutput(html);
}

Check out the Apps Script documentation Getting Started and Tutorial sections to get an idea of how to develop with Apps Script.




回答2:


Here is how you can display information from a single cell using the Javascript charts API. Better ways may be available, I am not an expert. To get the snippet below working just add your spreadsheet url and set the range.

<html>
  <head>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">

      // https://google,developers.appspot.com/chart/interactive/docs/spreadsheets#gid
      google.load('visualization', '1', {packages: ['corechart', 'line']});
      google.setOnLoadCallback(drawChart);

      function drawChart() {
        // Add your sheets url and range below
        var spreadsheetUrl = "https://your sheets url here?range=A1";
        var query = new google.visualization.Query(spreadsheetUrl);
        query.send(handleQueryResponse);
      }

      function handleQueryResponse(response) {
        var dataTable = response.getDataTable();
        // https://developers.google.com/chart/interactive/docs/reference?hl=en#methods
        // getValue(rowIndex, columnIndex)
        document.getElementById("test").innerHTML = dataTable.getValue(0, 0);
      }
    </script>
  </head>

  <body>
    <p id="test"></p>
  </body>
</html>


来源:https://stackoverflow.com/questions/13699589/display-the-content-of-a-google-sheet-cell-in-a-web-page

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