typescriptoffice-scripts

Function to return all the data within a table


The following function returns the data of Table1 excluding the headers:

function main(workbook: ExcelScript.Workbook) {
    let ws = workbook.getWorksheet("Sheet1");
    return ws.getTable("Table1").getRangeBetweenHeaderAndTotal().getValues();
}

How do I get it to return ALL the data, including the headers?


Solution

  • Please try.

    function main(workbook: ExcelScript.Workbook) {
      let ws = workbook.getWorksheet("Sheet1");
      return ws.getTable("Table1").getRange().getValues();
    }
    

    Microsoft documentation:

    getRange()