Transfer a HTML table (user input) to google sheets

前端 未结 1 540
无人及你
无人及你 2020-12-22 10:17

i want to transfer some user input data from a html page to my google sheet with google´s app scripts. I can do that for single values but could not figure out a nice way to

相关标签:
1条回答
  • 2020-12-22 10:29

    You can use Sheets API to parse and paste HTML directly.

    FrontEnd.html Snippet:

    let table = document.getElementById('tbl_posts').outerHTML;
    google.script.run.pasteHtml(table);
    

    Code.gs Snippet:

    function pasteHtml(table) {
      var ss = SpreadsheetApp.getActive();
      var req = {
        requests: [
          {
            pasteData: {
              html: true,
              data: table,
              coordinate: {
                sheetId: ss.getSheets()[1].getSheetId(), //second sheet!A1
                rowIndex: 0,
                columnIndex: 0,
              },
            },
          },
        ],
      };
      Sheets.Spreadsheets.batchUpdate(req, ss.getId());
    }
    

    To Read:

    • pasteData Request
    • Enabling Sheets Advanced Services
    0 讨论(0)
提交回复
热议问题