Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting an excel sheet in landscape mode from XLWT

Tags:

python

excel

xlwt

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.

like image 235
TimothyAWiseman Avatar asked Jul 14 '10 17:07

TimothyAWiseman


People also ask

How do I make my Excel spreadsheet landscape?

On the Page Layout tab, in the Page Setup group, click Orientation, and then click Portrait or Landscape.

Can you have portrait and landscape in the same Excel document?

Thus, you can set some as landscape and some as portrait and later just print the whole workbook. Excel keeps track and orients the printing properly for each worksheet. Here's the easy way to set orientation for a group of worksheets: Click the tab of the first worksheet.


2 Answers

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

worksheetObject.portrait = False
like image 158
Mark Avatar answered Oct 21 '22 06:10

Mark


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.

like image 42
Pietro Battiston Avatar answered Oct 21 '22 06:10

Pietro Battiston