簡體   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還很陌生,我的試驗只是導致了錯誤,如果有人幫助我,我會很高興的。

由於沒有提供有關源文件和目標文件以及選擇數據並將數據放入哪個單元格的特定信息,因此我提供了一個通用解決方案。 您可以使用它並識別源單元格和目標單元格來復制粘貼值。 除了被覆蓋的值外,目標文件不會發生任何變化。 樣式等將保持原樣。 希望這可以幫助。

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM