内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用
我想写张这样的表格:
---------------- | Long Cell | ---------------- | 1 | 2 | ----------------
如何编写单元格Long Cell?
试过这样做:
sheet.write(0, 0, 'Long Cell') sheet.write(1, 0, 1) sheet.write(1, 1, 2)
但结果却是:
-------------------- | Long Cell | | -------------------- | 1 | 2 | --------------------
两个单元格合并为r1, r2, c1, c2
,并接受可选的style
参数。
最简单的调用:
sheet.write_merge(0, 0, 0, 1, 'Long Cell') sheet.write(1, 0, 1) sheet.write(1, 1, 2)
要更明确地说明调用是如何工作的:
top_row = 0 bottom_row = 0 left_column = 0 right_column = 1 sheet.write_merge(top_row, bottom_row, left_column, right_column, 'Long Cell')
或者,使用merge
:
sheet.write(top_row, left_column, 'Long Cell') sheet.merge(top_row, bottom_row, left_column, right_column)