我使用xlwt做一些Excel工作表生成,但似乎每当我尝试合并单元格时,Python就会抛出一个AssertionError,即使代码简单如下:
import xlwt
wb = xlwt.Workbook(encoding = 'latin-1')
ws = wb.add_sheet('hey')
ws.write_merge(0,0,8,0,"hi")
wb.save("test.xls")
有人可以帮我吗?我错过了什么?非常感谢你。
答案 0 :(得分:0)
TLDR;
也许你的电话应该是:
ws.write_merge(0,0,0,8,"hi")
阐释: 富勒堆栈跟踪:
AssertionError Traceback (most recent call last)
<ipython-input-6-c6b20b7b1b27> in <module>()
----> 1 ws.write_merge(0,0,8,0)
/usr/local/lib/python2.7/dist-packages/xlwt/Worksheet.pyc in write_merge(self, r1, r2, c1, c2, label, style)
1110
1111 def write_merge(self, r1, r2, c1, c2, label="", style=Style.default_style):
-> 1112 assert 0 <= c1 <= c2 <= 255
1113 assert 0 <= r1 <= r2 <= 65535
1114 self.write(r1, c1, label, style)
我相信(我不确定,但如果我在这里错了请纠正我)write_merge
用于将多个单元格(工作表的一部分)合并为一个单元格。参数是(我猜!)start_row,end_row,start_col,end_col resp。对我来说,c1 <= c2 and r1 <= r2
必须坚持拥有真正的部分才能合并到一个单元格中。
答案 1 :(得分:0)
write_merge方法的参数应按以下顺序工作: sheet.write_merge(start_row,end_row,start_col,end_col,“单元格值”) 例如:
<Server port="8005" shutdown="SHUTDOWN">
<Service name="Catalina">
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="300" minSpareThreads="25" maxIdleTime="60000" />
<Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"
executor="tomcatThreadPool" />
</Service>
</Server>