gpt4 book ai didi

python - xlutils.copy [python 2.7 - excel]

转载 作者:行者123 更新时间:2023-11-28 18:44:19 25 4
gpt4 key购买 nike

我是 python 的新手(以及一般的编程)。

我在使用 xlrdxlwtxlutils 访问 xlsx 工作簿时遇到问题(它是一个常见问题,但我没有找到适合我的解决方案)。

我应该为 py-excel 更改我的包吗?在那种情况下,哪个?

这是我的代码:

import xlrd
import xlwt
from xlutils.copy import copy as xlutils_copy

rd = xlrd.open_workbook("x:/PROJECTS/Papers/2014_Pasture/a.xlsx")
rdsh = rd.sheet_by_name("FR_PASTURE")

wrb = xlutils_copy(rd)
ws = wrb.get_sheet_by_name("FR_PASTURE")

我收到的错误:

Traceback (most recent call last):
File "X:\PROJECTS\Papers\2014_Pasture\AdjustXLSStats.py", line 28, in <module>
wrb = xlutils_copy(rd)
File "C:\Python27\lib\site-packages\xlutils-1.7.0-py2.7.egg\xlutils\copy.py", line 19, in copy
w
File "C:\Python27\lib\site-packages\xlutils-1.7.0-py2.7.egg\xlutils\filter.py", line 937, in process
reader(chain[0])
File "C:\Python27\lib\site-packages\xlutils-1.7.0-py2.7.egg\xlutils\filter.py", line 68, in __call__
filter.cell(row_x,col_x,row_x,col_x)
File "C:\Python27\lib\site-packages\xlutils-1.7.0-py2.7.egg\xlutils\filter.py", line 573, in cell
wtrow.set_cell_number(wtcolx, cell.value, style)
File "build\bdist.win-amd64\egg\xlwt\Row.py", line 203, in set_cell_number
self.__adjust_bound_col_idx(colx)
File "build\bdist.win-amd64\egg\xlwt\Row.py", line 78, in __adjust_bound_col_idx
raise ValueError("column index (%r) not an int in range(256)" % arg)
ValueError: column index (256) not an int in range(256)

安装的 xlutils 版本:1.7.0操作系统:Windows 8excel:office 20113

最佳答案

xlrdxlwtxlutils 用于访问xls 文件,尚未更新使用使用 xlsx 文件,这会导致您出现多个错误。

作为解决方法,现在有一个 Python 库 openpyxl可以轻松读写Excel xlsx/xlsm/xltx/xltm文件。

关于python - xlutils.copy [python 2.7 - excel],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22252978/

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