简体   繁体   English

如何通过将一个特定单元格中的数据作为变量从一个 Excel 存储到另一个 Excel 中来写入数据

[英]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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Openpyxl:代码无法将数据从一个 Excel 电子表格写入另一个 - Openpyxl: Code fails to write data from one Excel spreadsheet to another 使用Python(和DataNitro)将单元格从一个Excel工作簿中的特定工作表复制到另一个Excel工作簿中的特定工作表 - Using Python (and DataNitro) to copy cells from a particular sheet in one Excel workbook, to a particular sheet in another Excel workbook 将数据从一个 Excel 工作表复制到另一个 Excel 工作表 - Copy data from one excel sheet to another excel sheet Python Excel 将单元格样式从一个复制到另一个openpyxl - Python Excel copy cell style from one to another openpyxl 如何将数据从多个工作表的一个Excel文件复制到多个工作表的另一个Excel文件中 - How do I copy the data from one Excel file of multiple sheets to another Excel file of multiple sheets 如何使用 Python 从一个 excel 复制数据并打印到另一个 excel 的相应行 - how to use Python to copy data from one excel and print into corresponding row in another excel Python Excel(xlrd,xlwt) - 如何从一个单元格复制样式并将其放在另一个单元格上 - Python Excel (xlrd, xlwt) - How to copy a style from one cell and put it on another 从多个 excel 读取并写入一个文件 - Read from mutiple excel and write to one file 使用python将特定数据从一个Excel文件传输到另一个 - Transferring specific data from one excel file to another using python 如何使用python在一个Excel单元格中编写列表 - How to write a list in one excel cell using python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM