简体   繁体   中英

How do you convert a dynamic range into a table using Excel Scripts?

I am new to using excel scripts with power automate. Trying to convert some data to a table. The thing is the number of rows will differ each time.

I've done this in excel desktop, but not sure how to do it using an excel script.

The problem is finding the used range in excel(Office Scripts). Once you have it, i assume you know how to convert it to table.

function main(workbook: ExcelScript.Workbook) 
{
  // Get the current, active worksheet.
  let currentWorksheet = workbook.getActiveWorksheet();

  // Get the range containing all the cells with data or formatting.
  let usedRange = currentWorksheet.getUsedRange();

  // Log the range's address to the console.
  console.log(usedRange.getAddress());
}

Link for your reference

From: https://learn.microsoft.com/en-us/office/dev/scripts/resources/samples/excel-samples

function main(workbook: ExcelScript.Workbook) {
  // Get the current worksheet.
  let selectedSheet = workbook.getActiveWorksheet();

  // Create a table with the used cells.
  let usedRange = selectedSheet.getUsedRange();
  let newTable = selectedSheet.addTable(usedRange, true);

  // Sort the table using the first column.
  newTable.getSort().apply([{ key: 0, ascending: true }]);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM