简体   繁体   English

使用xlwt将布尔值作为True或False写入excel文件

[英]write boolean values as True or False to excel file using xlwt

I am using xlwt ( docs ) for generating an excel sheet.I have used this django snippet to do it. 我正在使用xlwt( docs )生成Excel工作表。我已经使用了这个 django代码段来做到这一点。 The only issue I am facing is I have a column in excel sheet which has boolean values which appear as 1 or 0 , but I want True or False. 我面临的唯一问题是我在excel工作表中有一列具有显示为1或0的布尔值,但是我想要True或False。 I tried many things like 我尝试了很多类似的事情

DEFAULT_STYLE = xlwt.Style.default_style

and I also tried to force default style for this column as per article here I think it is possible.I also tried to remove this line 我也试图强行默认样式此列按文章在这里 ,我认为这是possible.I也试图删除此行

(bool,          xlwt.easyxf(num_format_str='BOOLEAN')),

to check if that would work but all in vain. 检查这是否有效,但徒劳无功。 Plus docs were not much of help either.Can anybody suggest some changes to the snippet mentioned here to allow boolean values to appear as True or False. 加上文档也没有太大帮助,有人可以建议对此处提到的代码段进行一些更改以使布尔值显示为True或False。 Thanks for your time 谢谢你的时间

I know Its too late to answer this question. 我知道回答这个问题为时已晚。

I was also stuck with this problem today. 今天我也被这个问题困扰。

In Most of the cases this type of problem will fix using 在大多数情况下,此类问题可以通过使用

label= 'bool' 标签='布尔'

according to doc https://xlwt.readthedocs.io/en/1.0.0/api.html 根据文档https://xlwt.readthedocs.io/en/1.0.0/api.html

sheet.write(r, c, label='bool', style)

If it is not working for you then use value in string 如果对您不起作用,请在字符串中使用value

sheet.write(row, col, str(value))

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

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