简体   繁体   English

Python/xlwings 将 excel 表格样式设置为“无”

[英]Python/xlwings set excel table style to "none"

I have exported a dataframe to Excel using xlwings and am trying to format it as a table.我已经使用 xlwings 将 dataframe 导出到 Excel 并尝试将其格式化为表格。 I want to apply the "None" style but can't figure out how to specify the "None."我想应用“无”样式,但不知道如何指定“无”。

This line works:这条线有效:

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

But instead of "TableStyleLight1" I want "None".但我想要“无”而不是“TableStyleLight1”。 I have tried "", '', 0, "None" and none of them work.我试过 "", '', 0, "None" 但它们都不起作用。

You can use .api to access the native object, and clear the formatting after creating the table:可以使用.api访问原生的object,建表后清除格式:

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

But as mentioned in the comments, it doesn't seem to be supported using tables.add directly.但正如评论中提到的,直接使用tables.add似乎不支持。 xlwings has a missing feature page with an example on using .api . xlwings缺少一个功能页面,其中包含使用.api的示例。 Note the above example is for windows, the api for mac is slightly different.注意上面的例子是针对 windows 的,针对 mac 的 api 略有不同。

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

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