xlwt – 如何将分页符添加到Excel文件?

我试图在Excel中使用Python和xlwt更改列值时添加分页符。

有谁知道如何做到这一点?

我find了一个例子,但是他们并没有真正地说出他们的代码是否工作,他们也没有说出元组中数字的含义:

ws.horz_page_breaks = [(54, 0, 255), (108, 0, 255)] 

做一些networking研究,我发现这个OpenOffice.org文档描述Excel的格式和BIFFlogging。 水平rest似乎(第181页),每个元组代表:

  • 低于分页符的第一行索引
  • 索引到分页符的第一列
  • 索引到分页符的最后一列

因此,对于在问题中显示的示例,您有两个分页符,一个在第54行,另一个在第108行,它们都从第0列到第255列。

同样适用于垂直断裂; 只是在上面的描述中交换“行”和“列”。

挖掘xlwt的源代码,结果{vert,horiz}_page_breaks是属性(参见源代码分发中的Worksheet.py ),最终被传递给BIFFRecords.{Vertical,Horizontal}PageBreaksRecord (见BIFFRecords.py )。 最后两个类logging。 这里是他们的文档,以防万一你觉得它们有用:

 class HorizontalPageBreaksRecord(BiffRecord): """ This record is part of the Page Settings Block. It contains all horizontal manual page breaks. Record HORIZONTALPAGEBREAKS, BIFF8: Offset Size Contents 0 2 Number of following row index structures (nm) 2 6nm List of nm row index structures. Each row index structure contains: Offset Size Contents 0 2 Index to first row below the page break 2 2 Index to first column of this page break 4 2 Index to last column of this page break The row indexes in the lists must be ordered ascending. If in BIFF8 a row contains several page breaks, they must be ordered ascending by start column index. """ class VerticalPageBreaksRecord(BiffRecord): """ This record is part of the Page Settings Block. It contains all vertical manual page breaks. Record VERTICALPAGEBREAKS, BIFF8: Offset Size Contents 0 2 Number of following column index structures (nm) 2 6nm List of nm column index structures. Each column index structure contains: Offset Size Contents 0 2 Index to first column following the page break 2 2 Index to first row of this page break 4 2 Index to last row of this page break The column indexes in the lists must be ordered ascending. If in BIFF8 a column contains several page breaks, they must be ordered ascending by start row index. """