Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用xlutils.copy在Excel文件中写入时出错_Python - Fatal编程技术网

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

Python 使用xlutils.copy在Excel文件中写入时出错,python,Python,我尝试在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(

我尝试在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
中转换一些值

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

'3'
不是
int
。如果没有失败的代码示例,包括完整的回溯,就很难准确地找出问题所在。