[英]How to Write Data from one particular cell by storing it as a variable from one Excel to Another Excel
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.