How to get Sheet Data as a table in Google Docs

Sheet data as table in doc
Select all the sheet data range as an array of values

Get the values as a nested array of array items.

[[First, Last, id], [Laurence, Svekis, 3.0], [Jane, Doe, 44.0], [Joe 1, Smith 2, 23324.0], [Joe 2, Smith 3, 234243.0], [Joe 3, Smith 4, 23432.0], [Joe 4, Smith 5, 243234.0]]

Select the doc and use the appendTable to the body of the document.


const SHEETID = ‘1u7vPqjklpmn8ygU’;
const DOCID = ‘1yoV_oFO-v7963hhIrY’;

function getValues1() {
const ss = SpreadsheetApp.openById(SHEETID);
const sheet = ss.getSheets()[0];
const range = sheet.getDataRange();
const data = range.getValues();
return data;

function createTableDoc(){
const doc = DocumentApp.create(‘doc1’);

function updateDoc(){
const doc =DocumentApp.openById(DOCID);
const body = doc.getBody();
const cells = getValues1();