Python XlsxWriter - Page Setup



The worksheet page setup methods are related to appearance of the worksheet when it is printed. These worksheet methods control the orientation, paper size, margins, etc.

set_landscape()

This method is used to set the orientation of a worksheet's printed page to landscape.

set_portrait()

This method is used to set the orientation of a worksheet's printed page to portrait. This is the default orientation.

set_page_view()

This method is used to display the worksheet in "Page View/Layout" mode.

set_paper()

This method is used to set the paper format for the printed output of a worksheet. It takes index as an integer argument. It is the Excel paper format index.

Following are some of the paper styles and index values −

Index Paper format Paper size
0 Printer default Printer default
1 Letter 8 1/2 x 11 in
2 Letter Small 8 1/2 x 11 in
3 Tabloid 11 x 17 in
4 Ledger 17 x 11 in
5 Legal 8 1/2 x 14 in
6 Statement 5 1/2 x 8 1/2 in
7 Executive 7 1/4 x 10 1/2 in
8 A3 297 x 420 mm
9 A4 210 x 297 mm

set_margin()

This method is used to set the margins of the worksheet when it is printed. It accepts left, right, top and bottom parameters whose values are in inches. All parameters are optional The left and right parameters are 0.7 by default, and top and bottom are 0.75 by default.

Advertisements