8

I have a Python program that creates an excel sheet, but I have been asked by one of the users to modify it so that if he hits print it will print out to landscape mode, without him having to specify this. Is there some way to set the sheet to landscape in XLWT or some similar Python library for excel?

Thank you.

TimothyAWiseman
  • 14,385
  • 12
  • 40
  • 47

2 Answers2

8

With XLWT, I believe it's as easy as:

worksheetObject.portrait = False
Mark
  • 106,305
  • 20
  • 172
  • 230
4

I think Mark's answer was valid with previous versions of xlwt, it does not work as of version 0.7.5. The following works instead:

sheet.set_portrait(False)

Notice it is now a property of the sheet, not of the whole workbook.

Pietro Battiston
  • 7,930
  • 3
  • 42
  • 45