我尝试创建一个办公脚本,与此 excel makro 执行相同的操作:
Sub clear()
Rows("2:" & Rows.Count).ClearContents
End Sub
我的办公室脚本如下所示:function main(workbook: ExcelScript.Workbook)
{
let table = workbook.getTable("Table1");
let rowCount = workbook.getTables()[0].getRowCount();
table.deleteRowsAt(2, rowCount);
}
我收到以下错误:Line 9: Cannot read property 'deleteRowsAt' of undefined
我不明白为什么属性“deleteRowsAt”未定义。它需要是一个办公脚本,因为我想用电源自动化来自动化一个过程。
最佳答案
不知道为什么你没有在 rowCount 代码中使用 table。你不知道你是否能确定得到那张 table 。
假设您的表格从第 2 行开始,并且标题在第 1 行,要删除表格,请参见下面的代码。
function main(workbook: ExcelScript.Workbook) {
let table = workbook.getTable("Table1");
let rowCount = table.getRowCount();
table.deleteRowsAt(0, rowCount);
}
关于excel - Excel 中的 Office 脚本 "Delete All Rows Except The First Header Row",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68343062/