本文介绍了条件格式xlwt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过一些帖子说你不能使用 xlwt 来执行条件格式化,但是他们相当老了。我很好奇,如果这个演变?

我现在一直在搜索大概半天。此外,如果我不直接从 xlwt 写入,我可以创建包含单个单元格的 .xls 文件以我想要的条件格式,并有 xlrd 读取该格式,并将其粘贴到我打算生成的工作表中,然后使用 xlwt / code> still 不支持条件格式化 xlrd 不会读取, xlwt 不会写入。



有一个新的和真棒模块,称为。开箱即用支持 。该项目是积极的,文件是相当不错的。此外,还有很多。



下面是一个例子:

  from xlsxwriter.workbook import Workbook 

workbook = Workbook('test.xlsx')
worksheet = workbook.add_worksheet()

worksheet.write('A1',49)
worksheet.write('A2',51)

format1 = workbook.add_format({'bold':1,'italic':1})
worksheet.conditional_format('A1:A2 ',{'type':'cell',
'criteria':'> =',
'value':50,
'format':format1})
workbook.close()


I have seen some posts that say you can NOT perform conditional formatting using xlwt, but they were rather old. I was curious if this has evolved?

I have been searching for about half a day now. Furthermore, if I con't write it directly from xlwt, can I create an .xls file containing a single cell with the conditional format I want and have xlrd read that format and paste it into the sheet I aim to produce then using xlwt?

解决方案

xlrd and xlwt still don't support conditional formatting. xlrd doesn't read it, xlwt doesn't write it.

There is a new and awesome module, called xlsxwriter. It does support conditional formatting out of the box. The project is active, documentation is pretty good. Plus, there are a lot of examples.

Here's an example:

from xlsxwriter.workbook import Workbook

workbook = Workbook('test.xlsx')
worksheet = workbook.add_worksheet()

worksheet.write('A1', 49)
worksheet.write('A2', 51)

format1 = workbook.add_format({'bold': 1, 'italic': 1})
worksheet.conditional_format('A1:A2', {'type': 'cell',
                                       'criteria': '>=',
                                       'value': 50,
                                       'format': format1})
workbook.close()

这篇关于条件格式xlwt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-12 05:18