我对 Python 非常陌生,正在尝试创建和打印 Excel 电子表格。郑重声明一下,我在 C 和 C++ 编程方面拥有多年的经验。我在 Windows 7 上使用 Python 3.5.1 和 OpenPyxl 并使用 xlsx 文件。下面复制了我用来重复前 2 行作为重复页眉的代码片段:
import openpyxl
from openpyxl.workbook import Workbook
from openpyxl.worksheet.properties import WorksheetProperties
...
sheet.print_options.gridLines = True
sheet.print_title_rows = '1:2' #**problem code not working as intended**
sheet.page_setup.orientation = sheet.ORIENTATION_LANDSCAPE
...
Run Code Online (Sandbox Code Playgroud)
除活动工作表中 print_title_rows 的赋值语句外,上述所有其他设置均按预期工作。如果论坛上的专家们能够为我指明正确的方向,我将非常感激。珍惜您的时间。