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:

3
  • 2
    Try play around with pring_scaling and paper_size_code worksheet properties. Also see the full list of workheet properties.
    – alecxe
    Mar 14, 2014 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().
    – alecxe
    Mar 19, 2014 at 0: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, 2014 at 23:13

1 Answer 1

4
+50

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, ...

1
  • 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, 2016 at 21:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.