Python/xlwings 将 excel table 样式设置为 "none"

Python/xlwings set excel table style to "none"

我已经使用 xlwings 将数据帧导出到 Excel,并试图将其格式化为 table。我想应用“None”样式,但不知道如何指定“None”。

这一行有效:

table = sheet.tables.add(source=sheet["A1"].expand(), name = 'TableName', table_style_name = "TableStyleLight1")

但我想要“None”而不是“TableStyleLight1”。我试过 "", '', 0, "None" 和 none 它们的工作。

可以使用.api访问原生对象,创建table后清除格式:

table = sheet.tables.add(source=ws.range('I20:N40'), name='UnformattedTable')
sheet.api.ListObjects('UnformattedTable').TableStyle = ""  # Windows specific

但是评论里说了,好像不支持直接使用tables.add。 xlwings 有一个 missing feature 页面,其中包含使用 .api 的示例。请注意,上面的示例是 windows,mac 的 api 略有不同。