The parameters (number[]) don't match the method signature for DocumentApp.Body.appendTable

89 Views Asked by At

In Apps Script, create a menu where the user selects a range of cells and hits a button that activates the following function. With:

var dataRange = dataSheet.getActiveRange();
var dataValues = dataRange.getValues();

I transform the selection of the user in an array, but when I want to insert it in a table of a doc with :

  var doc = DocumentApp.create(fileName.getResponseText());
  var docID = doc.getId();
  var file = DriveApp.getFileById(docID);
  file.moveTo(destination);
  var body = doc.getBody();

  table = body.appendTable(dataValues);

I get the error in the title.

The format of the array is

[[HEADER C1,HEADER D1,HEADER E1,HEADER F1],[C2,D2,E2,F2],[C3,D3,E3,F3],[C4,D4,E4,F4]]
1

There are 1 best solutions below

0
Cooper On

This works for me:

function totest() {
  const folder = DriveApp.getFolderById(gobj.globals.testfolderid);
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName("Sheet0");
  const vs = sh.getDataRange().getValues();
  const r = SpreadsheetApp.getUi().prompt("Enter Document Name", "Enter Document Name", SpreadsheetApp.getUi().ButtonSet.OK_CANCEL);
  if (r.getSelectedButton() == SpreadsheetApp.getUi().Button.OK) {
    const doc = DocumentApp.create(r.getResponseText());
    const file = DriveApp.getFileById(doc.getId());
    file.moveTo(folder);
    var body = doc.getBody();
    let table = body.appendTable(vs);
  }
}

What do you mean when you say I transform the selection of the user in the array. Be specific. There is something your are not telling us.