Python,openpyxl:运行get_highest_column()

时间:2015-10-13 21:38:20

标签: python openpyxl

我正在练习openpyxl,我正在开发名为'test.xlsx'的Excel文件。该文件只有3列7行。 .xlsx文件是使用LibreOffice创建的。

当我跑...

>>> #! python3 
>>> import openpyxl
>>> wb = openpyxl.load_workbook('test.xlsx')
>>> sheet = wb.get_sheet_by_name('Sheet1')
>>> sheet.get_highest_column()
1025

返回的值应为3。

Google快速搜索建议我运行:

>>> sheet.calculate_dimension()

并获得了返回值:

'A1:AMK7'

这应该只是'A1:C7'

我记得读过LibreOffice可能是问题的一部分。 但是,我无法切换到MSOffice,我讨厌OpenOffice。

是否有关于如何解决此问题或解决此问题的建议? 谢谢!

1 个答案:

答案 0 :(得分:1)

听起来你正在使用旧版本的LibreOffice和openpyxl。 LibreOffice曾经为尺寸设置了默认值“A1:AMK7”,但版本5似乎不再这样做了。 openpyxl曾经在读取文件时依赖维度标记,但暂时还没有这样做。请尝试使用openpyxl 2.3-b2