4

每当使用 Python 和xlwt在 Excel 中更改列的值时,我都会尝试添加分页符。

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

我找到了一个例子,但他们并没有真正说明他们的代码是否有效,也没有说明元组中的数字意味着什么:

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

2 回答 2

5

在进行一些网络研究时,我发现了这个描述 Excel 格式和 BIFF 记录的OpenOffice.org 文档。似乎对于水平中断(第 181 页),每个元组代表:

  • 索引到分页符下方的第一行
  • 分页符第一列的索引
  • 分页符最后一列的索引

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

同样适用于垂直中断;只需交换前面描述中的“行”和“列”即可。

于 2011-12-30T16:28:40.617 回答
2

挖掘 xlwt 的源代码,结果{vert,horiz}_page_breaks是属性(参见Worksheet.py源代码分发版)最终被传递给BIFFRecords.{Vertical,Horizontal}PageBreaksRecord(参见参考资料BIFFRecords.py)。最后两个类记录在案。这是他们的文档,以防您发现它们有用:

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.
    """
于 2011-12-30T16:35:55.700 回答