简体   繁体   English

如何使用 Excel 脚本将动态范围转换为表格?

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

I am new to using excel scripts with power automate.我不熟悉将 excel 脚本与电源自动化结合使用。 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.我已经在 excel 桌面上完成了此操作,但不确定如何使用 excel 脚本进行操作。

The problem is finding the used range in excel(Office Scripts).问题是在 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来自: 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 }]);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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