0
votes

Is there a way to create a table in Excel using office js with custom headers.

As of now, any table am creating has the default headers as - Column1, Column2 etc ..

I want to over ride the same with any custom header names like Header1,Header2 etc.

Is there any way to do so?

Am creating the table in the following manner -

var table = ctx.workbook.tables.add(wSheetName + "!A1:N1", true).load("name");

1

1 Answers

0
votes

You have 2 options, if you create your table on top of the range that already has values, then those values will automatically be carried forward as the column names.

 var range = ctx.workbook.worksheets.getItem("Tables").getRange("A23:B25");
 range.values = [["header1", "header2"],         
 ["value1", "value2"],   
 ["value1", "value2"]];
 var table = ctx.workbook.tables.add("Tables!A23:B25", true);

The other option is to have the table created with the default names and then get the header row and set it's values like this:

var table = ctx.workbook.tables.add(TABLEADDRESS, true);
table.getHeaderRowRange().values = [["foo", "bar"]];

-Philip, Software Engineer on the Office Extensibility team