我想使用openpyxl在excel中连接两个单元格。但我正在努力使代码正确地进入“for循环”,因为我必须迭代和浓缩单元格
import openpyxl
wk=openpyxl.load_workbook(r"C:\\Users\\hp\\Desktop\\Uarch\\ConcatDemo.xlsx")
sh=wk['Sheet1']
rows=sh.max_row
columns=sh.max_column
for row_num in range(1,rows+1):
sh['C{}'.format(row_num)] = '=CONCATENATE(A{},",",B{})'.format(row_num)
wk.save(r"C:\\Users\\hp\\Desktop\\Uarch\\ConcatDemo.xlsx")
我越来越
IndexError: tuple index out of range
Erro屏幕截图:
不确定哪一部分出错了,或者我的逻辑错误了
输入:
预期产出:
期待在这方面得到帮助
问题是,本节中的字符串格式在串联函数中需要2个值,而不是1个值
我可以用这个达到你想要的行为
隔离错误
这也可以通过熊猫来实现
相关问题 更多 >
编程相关推荐