使用xlutils.copy在Excel文件中写入时出错



我尝试在Excel文件中写入一个值(格式为.xlsx(。

所以我写了这个代码:

import xlrd
from xlutils.copy import copy
from robot.api import logger
def set_value_in_excel(filename, sheet_num, row_index, column_index, value):
logger.console(filename) // myfile.xlsx
logger.console(sheet_num) // 0
logger.console(row_index) // 1
logger.console(column_index) // 3
logger.console(value) // False
rb = xlrd.open_workbook(filename)
wb = copy(rb)
sheet = wb.get_sheet(int(sheet_num))
sheet.write(row_index, column_index, value)
wb.save(filename)

但我得到了这个错误:

ValueError:列索引('3'(不是范围(256(中的int

你能帮我吗?

解决方案

需要转换int中的一些值。

sheet.write(int(row_index), int(column_index), value)

最新更新