openpyxl - 设置用于打印的自定义纸张尺寸 [英] openpyxl - set custom paper size for printing
问题描述
我想使用openpyxl
将纸张尺寸打印选项设置为A6或自定义用户尺寸模板,代码如下:
I want to set the paper size print option to A6 or a custom user size template with openpyxl
, the code would be as follows:
workbook = Workbook()
ws = workbook.active
ws.page_setup.paperSize = ws.PAPERSIZE_CUSTOM
不幸的是,从文档来看,似乎唯一可用的枚举尺寸是:
unfortunately, from the docs, it seems the only enumerated sizes available are:
PAPERSIZE_LETTER = '1'
PAPERSIZE_LETTER_SMALL = '2'
PAPERSIZE_TABLOID = '3'
PAPERSIZE_LEDGER = '4'
PAPERSIZE_LEGAL = '5'
PAPERSIZE_STATEMENT = '6'
PAPERSIZE_EXECUTIVE = '7'
PAPERSIZE_A3 = '8'
PAPERSIZE_A4 = '9'
PAPERSIZE_A4_SMALL = '10'
PAPERSIZE_A5 = '11'
我已经尝试将纸张高度和纸张宽度设置为我的自定义属性:
I've tried setting the paper height and paper width to my custom properties as such:
#ws.page_setup.paperSize = ws.PAPERSIZE_A6
ws.page_setup.paperHeight = '105mm'
ws.page_setup.paperWidth = '148mm'
但是,在通过 excel 打印时,我仍然需要使用下拉对话框选择A6",然后才能打印到正确的纸张尺寸.
however, when printing thru excel, I still have to use the drop down dialog to select 'A6' before I can print to the correct paper size.
有没有办法做到这一点?或达到类似的效果?如果重要的话,我使用的是 Mac OS.
Is there a way I can do this? or achieve a similar effect? I'm on Mac OS if that matters.
推荐答案
问题:为打印设置自定义纸张尺寸
Question: set custom paper size for printing
从文档来看,似乎唯一可用的枚举尺寸是......
缺失值,来自 OpenOffice:
The missing values, from OpenOffice:
- A6:
70
- 自定义:
0
值必须是 int
类型.
尝试使用:
ws.page_setup.paperSize = 70
# or
ws.set_printer_settings(70, ORIENTATION_PORTRAIT)
不改变 Format => Page => [Page]
设置.
does not change Format => Page => [Page]
settings.
这对我有用:
ws.page_setup.paperHeight = '105mm'
ws.page_setup.paperWidth = '148mm'
Format => Page => [Page]
设置更改为 User:
高度/宽度
.
The Format => Page => [Page]
setting are changed to User:
with the given Height/Width
.
我建议使用以下内容:
ws.set_printer_settings(0, ORIENTATION_PORTRAIT)
ws.page_setup.paperHeight = '105mm'
ws.page_setup.paperWidth = '148mm'
使用 Python 测试:3.4.2 - openpyxl:2.4.1 - LibreOffice:5.2.7.2
这篇关于openpyxl - 设置用于打印的自定义纸张尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!