Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resize a table in Excel through the JavaScript API?

In Excel, a table can be resized by dragging its lower-right corner, which makes a table bigger (or smaller) without inserting (or removing) any cells in the worksheet (see “Sizing handle” in Microsoft’s “Overview of Excel tables”). The equivalent action can be done through the VBA API using “ListObject.resize”: “The Resize method allows a ListObject object to be resized over a new range. No cells are inserted or moved.”

How can this be done through the JavaScript API? I’m probably overlooking the obvious, but the class “Table” at least doesn’t seem to offer a method “resize”.

like image 433
Rinzwind Avatar asked Sep 13 '26 08:09

Rinzwind


1 Answers

Good news, we have created this API and We release table.resize() last month together with SAC, now you could try it out. here is the code sample。

await Excel.run(async (context) => {
  // Retrieve the worksheet and a table on that worksheet.
  const sheet = context.workbook.worksheets.getItem("Sample");
  const expensesTable = sheet.tables.getItem("ExpensesTable");
  
  // Resize the table.
  expensesTable.resize("A1:D20");
  
  await context.sync();
});
like image 196
Raymond Lu Avatar answered Sep 15 '26 01:09

Raymond Lu