7

Summary: How do I set the print range settings from xlwt?

I have a document that is currently set as four pages for the purposes of printing, and I need to make it so that the print range is set to only treat it as one page. The documentation for xlwt (outside of the basics) is hard to find.

The only things I've been able to find so far are:

Felix
  • 4,510
  • 2
  • 31
  • 46
Havvy
  • 1,471
  • 14
  • 27
  • 2
    Try play around with `pring_scaling` and `paper_size_code` worksheet properties. Also see the full [list of workheet properties](https://github.com/python-excel/xlwt/blob/master/xlwt/examples/wsprops.py). – alecxe Mar 14 '14 at 19:57
  • Also, think about `xlsxwriter` module, it generates `xlsx`, but it's much more pleasant and easy to work with, in particular see [fit_to_pages()](http://xlsxwriter.readthedocs.org/page_setup.html#fit_to_pages). – alecxe Mar 19 '14 at 00:45
  • There are so many things that xlsxwriter doesn't copy from an xlsx that I could not use it. I had also considered the ODS libraries. – Havvy Mar 19 '14 at 23:13

1 Answers1

4

Try

worksheet.fit_num_pages=1

Or worksheet.set_fit_num_pages(1) both of which shrinks everything to fit on one page. The default value is set to 0 meaning no scaling happens.

ws.print_scaling is a scaling percentage, set by default to 100.

ws.paper_size_code defaults to 9 on my system, but presumably lets you choose between A3, A4, ...

pandita
  • 4,739
  • 6
  • 29
  • 51
  • Great answer, I was digging for something like this for several days. Little update from my side: on my system, `ws.paper_size_code = 1` will use A4, `ws.paper_size_code = 2` will use Letter and `ws.paper_size_code = 11` will use A5 paper size. I suspect that those settings will depend on region. – Fejs Dec 18 '16 at 21:55