Python Xlsxwriter 简明教程

Python XlsxWriter - Page Setup

工作表 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()

此方法用于设置工作表打印输出的纸张格式。它采用索引作为整数参数。这是 Excel 纸张格式索引。

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()

此方法用于设置工作表在打印时的边距。它接受值为英寸的 left、right、top 和 bottom 参数。所有参数都是可选的。左侧和右侧参数默认值为 0.7,上方和下方默认值为 0.75。

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.