问题描述
我有一个新创建的带有一张纸的 xlsx 工作簿.A1:A2 被合并并包含字符串 'test'.
I have a newly created xlsx workbook with one sheet. A1:A2 is merged and contains the string 'test'.
使用 openpyxl (2.3.0) 我可以访问工作表和单元格值,但 worksheet.merged_cell_ranges
和 worksheet.merged_cells
都是空的:
Using openpyxl (2.3.0) I can access the sheet and the cell value but worksheet.merged_cell_ranges
and worksheet.merged_cells
are both empty:
wb = workbook.worksheets[0] # ReadOnlyWorksheet: <ReadOnlyWorksheet "Sheet1">
wb.cell(row=1, column=1) # 'test'
wb.merged_cell_ranges # list: []
wb.merged_cells # set: set([])
文档(http://openpyxl.readthedocs.org/en/latest/api/openpyxl.worksheet.html) 和其他 SO 问题的答案表明这不是预期的行为.
The documentation (http://openpyxl.readthedocs.org/en/latest/api/openpyxl.worksheet.html) and answers to other SO questions indicate that this is not the expected behaviour.
是的,单元格肯定是合并的.我做错了什么吗?
Yes, the cells are definitely merged. Am I doing something wrong?
推荐答案
以只读模式打开工作簿时,不会填充 merged_cells
和 merged_cell_ranges
属性.
The merged_cells
and merged_cell_ranges
properties are not populated when the workbook has been opened in read-only mode.
在查理克拉克的评论提示下,我打开了没有只读标志的工作簿,并且 merged_cells
和 merged_cell_ranges
属性被正确填充.
Prompted by Charlie Clark's comment, I opened the workbook without the read-only flag and the merged_cells
and merged_cell_ranges
properties were correctly populated.
已提交 错误 #540一>.
这篇关于openpyxl:merged_cell_ranges 和merged_cells 都是空的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!