gpt4 book ai didi

python - 如何使用 Openpyxl 分割 Excel 屏幕?

转载 作者:太空宇宙 更新时间:2023-11-03 21:09:53 28 4
gpt4 key购买 nike

我一直在尝试使用 Openpyxl 垂直分割 Excel 屏幕(在 Excel 中,功能区“ View ”选项卡中的“分割”按钮)。我还没有找到任何指南,如何做到这一点。但我找到了这个网页( https://openpyxl.readthedocs.io/en/stable/api/openpyxl.worksheet.views.html ),我认为“ySplit”属性可能是解决方案。不幸的是我还没能弄清楚如何正确使用它。我尝试过以下代码:

wb = openpyxl.load_workbook('file.xlsx')
sh = wb.active
sh.sheet_view.pane.ySplit = 20

EDIT: But this code does not work: AttributeError: 'NoneType' object has no attribute 'ySplit'.

我还尝试了上面代码的一些变体(使用 ySplit)。但没有成功。如果有人能帮助我找到一种方法,如何分割屏幕,我将不胜感激。

提前致谢。

EDIT2: The solution was provided by stovfl in comments. The code should be:

sh.sheet_view.pane = openpyxl.worksheet.views.Pane(xSplit=20.0, ySplit=None, topLeftCell='C1', activePane='topLeft', state='split')

最佳答案

Question How to split Excel screen with Openpyxl?

要定义、显示拆分的工作表,您必须创建 openpyxl.worksheet.views.Pane对象并将其分配给 myWorksheet.sheet_view.pane .

from openpyxl.worksheet.views import Pane

wb = openpyxl.load_workbook('file.xlsx')
ws = wb.active

ws.sheet_view.pane = Pane(xSplit=20.0, ySplit=None,
topLeftCell='C1', activePane='topLeft', state='split')

wb.save('file.xlsx')

openPyXL - worksheet.views.Pane

class openpyxl.worksheet.views.Pane(xSplit=None, ySplit=None, 
topLeftCell=None,
activePane='topLeft', state='split')[source]

activePane
Value must be one of {‘topLeft’, ‘bottomRight’, ‘topRight’, ‘bottomLeft’}

state
Value must be one of {‘split’, ‘frozen’, ‘frozenSplit’}

topLeftCell
Values must be of type <class ‘str’>

xSplit
Values must be of type <class ‘float’>

ySplit
Values must be of type <class ‘float’>

关于python - 如何使用 Openpyxl 分割 Excel 屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55141377/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com