将值附加到特定列 openpyxl [英] Append values to specific column openpyxl
本文介绍了将值附加到特定列 openpyxl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
试图从 ws2 中获取一组数据并附加到 ws3 的底部.我正在努力附加到 ws3 上的特定列.
Trying to take a set of data from ws2 and append to the bottom of ws3. I'm struggling to append to a specific column on ws3.
目前,所有内容都只是附加到 A 列,尽管我希望它附加到 ws2 中信息来自的相同列.
Currently, everything just appends to column A, although I want it to append to the same columns where the information is coming from in ws2.
#where I want to copy data from:
for col in ws2.iter_cols(min_row=2,min_col=4,max_col=6):
for cell in col:
ws3.append([cell.value])
wb3.save('example3.xlsx')
帮助!
推荐答案
您只能追加行,但您可以轻松地调整您的代码以处理此问题:
You can only append rows, but you can easily adjust your code to work with this:
for col in ws2.iter_rows(min_row=2,min_col=4,max_col=6):
row = [None]*3 + [cell.value for cell in col]
ws3.append(row)
这篇关于将值附加到特定列 openpyxl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文