首页 > 解决方案 > How to Clear Table Style in Office Scripts?

问题描述

How can I clear the styles on a table? I tried recording the macro but when I record it and run it, it will say failed (Table setPredefinedTableStyle: The argument is invalid or missing or has an incorrect format.).

function main(workbook: ExcelScript.Workbook) {
  let selectedSheet = workbook.getActiveWorksheet();
  let mainTable = selectedSheet.getTable("MainTable");
  mainTable.setPredefinedTableStyle("undefined");
}

How can I clear the table style?

https://docs.microsoft.com/en-us/javascript/api/office-scripts/excelscript/excelscript.table?view=office-scripts#setpredefinedtablestyle-predefinedtablestyle-

enter image description here

标签: exceltypescriptoffice-scripts

解决方案


Excel tables in web always has a style. There isn't a way to clear all styles. There doesn't appear to be a way to assign the "none" style, which is the most basic style. I'll follow-up on that.

enter image description here

The closest I can get to was to use TableStyleLight1 style as shown below.

function main(workbook: ExcelScript.Workbook) {
  let selectedSheet = workbook.getActiveWorksheet();
  let mainTable = selectedSheet.getTable("MainTable");
  mainTable.setPredefinedTableStyle('TableStyleLight1')
}

推荐阅读