I'm trying to add page breaks whenever a column's value changes in Excel using Python and xlwt.
Does anyone know how to do this?
I found one example but they don't really say if their code works, and they don't say what the numbers mean in the tuple:
ws.horz_page_breaks = [(54, 0, 255), (108, 0, 255)]
Doing some web research I found this OpenOffice.org document describing Excel's format and BIFF records. It seems for horizontal breaks (pag. 181), each tuple represents:
So, for the example you show in the question, you have two page breaks, one over row 54 and another one over row 108, both of them spanning from column 0 to column 255.
Same applies for vertical breaks; just swap "row" and "column" in the previous description.
Digging in xlwt's source code, it turns out
{vert,horiz}_page_breaks
are properties (seeWorksheet.py
in the source distribution) that end up being passed toBIFFRecords.{Vertical,Horizontal}PageBreaksRecord
(seeBIFFRecords.py
). Those last two classes are documented. Here's the docs for them, in case you find them useful: