Python 类型错误:';活页';跨excel合并数据时,对象不可调用
我现在正在为2 excel文件合并数据。我的方法是使用Python 类型错误:';活页';跨excel合并数据时,对象不可调用,python,python-3.x,xlrd,xlwt,Python,Python 3.x,Xlrd,Xlwt,我现在正在为2 excel文件合并数据。我的方法是使用xlwt创建新的excel和相应的工作表。然后使用for循环写入新创建的excel文件。我的代码如下: #...... wbk = xlwt.Workbook() sheet_0 = wbk.add_sheet('A') sheet_1 = wbk.add_sheet('B') wbk.save(os.path.join(currentPath, gsheet.cell(gsr, 2).value) + Ful
xlwt
创建新的excel和相应的工作表。然后使用for循环写入新创建的excel文件。我的代码如下:
#......
wbk = xlwt.Workbook()
sheet_0 = wbk.add_sheet('A')
sheet_1 = wbk.add_sheet('B')
wbk.save(os.path.join(currentPath, gsheet.cell(gsr, 2).value) + FullName + " " + time_now + ".xls")
wkbk = xlrd.open_workbook(
os.path.join(currentPath, gsheet.cell(gsr, 2).value) + FullName + " " + time_now + ".xls")
wb_merge = copy(wkbk)
wsheet_0 = wb_merge.get_sheet(0)
wsheet_1 = wb_merge.get_sheet(1)
workbook_merge_0 = xlrd.open_workbook(os.path.join(currentPath, filename0), formatting_info=True)
sheet_merge_0 = workbook_merge_0.sheet_by_index(0)
for r in range(0, total_row_0):
for c in range(0, total_col_0):
wsheet_1.write(r, c, sheet_merge_0(r, c).value)
#......
当我运行整个代码时,error showTypeError:“Sheet”对象不可调用
,指向最后一行,即wsheet\u 1.write(r,c,Sheet\u merge\u 0(r,c).value)
可以提供任何建议吗?提前谢谢
工作表\u merge\u 0
是一个工作表
。你试图调用它,就好像它是一个函数一样。您可能想调用它的单元格
方法,就像前面在同一代码中对其他工作表所做的那样?好吧,基本问题很明显:sheet\u merge\u 0
是一个sheet
,但您试图像函数一样访问它。查看表
类文档;找到从工作表中获取特定单元格的正确语法。这个类应该有一个访问方法,或者你只需要括号而不是括号。谢谢!我被修改为sheet\u merge\u 0.cell(r,c).value
,它工作得非常好!