Office 脚本 - 如何删除最后一行

Office Scripts- How to delete last row

我正在尝试使用 Office 脚本删除 Excel 在线文档中的最后一行。

我不知道我做错了什么,不是删除,有没有人知道?

我的代码:

function main(workbook: ExcelScript.Workbook) {
    let selectedSheet = workbook.getActiveWorksheet();
    //getting the used range in the worksheet
    let usedRange = workbook.getActiveWorksheet().getUsedRange();
    //getting the row count of the used range
    let lastRow = usedRange.getRowCount();
    //getting the row count of the range
    let rowCount = usedRange.getRowCount();
    usedRange.getCell(lastRow, 0).getEntireRow().delete(ExcelScript.DeleteShiftDirection.up)
}

这样可能更万无一失...

function main(workbook: ExcelScript.Workbook) {
  let selectedSheet = workbook.getActiveWorksheet();
  let usedRange = selectedSheet.getUsedRange();  
  let lastRowAddress = usedRange.getLastCell().getAddress();
  selectedSheet.getRange(lastRowAddress).getEntireRow().delete(ExcelScript.DeleteShiftDirection.up);
}