繁体   English   中英

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

[英]xlwt - How to add page breaks to an Excel File?

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

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

我找到了一个例子,但他们并没有真正说出他们的代码是否有效,而且他们没有说出数字在元组中的含义:

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

做一些网络研究我发现这个OpenOffice.org文档描述了Excel的格式和BIFF记录。 似乎是横向休息(第181页),每个元组代表:

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

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

同样适用于垂直休息; 只需在前面的描述中交换“row”和“column”。

挖掘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.
    """

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM