简体   繁体   中英

How to Write Data from one particular cell by storing it as a variable from one Excel to Another Excel

我将在此处发布我的 Excel 屏幕截图这是我要从中复制数据的截图 在此处输入图像描述,我希望将其填写在此 Excel 中在此处输入图像描述我想将来自 excel 的数据存储在一个变量中并用它来填写另一个我对python还很陌生,我的试验只是导致了错误,如果有人帮助我,我会很高兴的。

As there is no specific information provided on the source and destination files and which cell to pick data and put into which cell, I am providing a generic solution. You can use this and identify source and destination cells to copy-paste values. There will be no change to the destination file, except for the values being overwritten. The style, etc. will remain as is. Hope this helps.

import openpyxl
wbsource = load_workbook('inputfile.xlsx') #Open source excel from which you want to copy
wssource = wbsource['Sheet4']   #Pick sheet you want to get the data from

wbdest = load_workbook('output.xlsx') #Open destination excel into which you want to paste
wsdest = wbdest['Sheet1']    #Pick sheet you want to paste the data to

wsdest.cell(row=11, column=1).value = wssource.cell(row=3, column = 1).value #Take "value" from source cell A3 and paste to dextination cell A11

# Put your other source and destination cells here
# ...

wbdest.save('output.xlsx') #Finally save the file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM