亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Openpyxl - 將單元格區域(帶公式)從工作簿復制到另一個工作簿

Openpyxl - 將單元格區域(帶公式)從工作簿復制到另一個工作簿

LEATH 2022-09-27 09:44:48
我正在嘗試從工作簿1中復制特定行,并將其追加到工作簿2中的現有數據中。從工作簿 1 中復制突出顯示的行,并將它們追加到“March”下方的工作簿 2 中到目前為止,我成功地復制并粘貼了范圍,但有兩個問題:1.單元格是移位的2.缺少百分比(公式),只留下數值。在此處查看結果import openpyxl as xlsource = r"C:\Users\Desktop\Test_project_20200401.xlsx"wbs = xl.load_workbook(source)wbs_sheet = wbs["P2"] #selecting the sheetdestination = r"C:\Users\Desktop\Try999.xlsx"wbd = xl.load_workbook(destination)wbd_sheet = wbd["A3"] #select the sheetrow_data = 0for row in wbs_sheet.iter_rows():    for cell in row:        if cell.value == "Yes":            row_data += cell.rowfor row in wbs_sheet.iter_rows(min_row=row_data, min_col = 1, max_col=250, max_row = row_data+1):    wbd_sheet.append((cell.value for cell in row))            wbd.save(destination)有沒有人知道我該如何解決這個問題?任何反饋/解決方案都會有所幫助!謝謝!
查看完整描述

2 回答

?
MMTTMM

TA貢獻1869條經驗 獲得超4個贊

我認為min_col應該= 0

范圍(“A1”)。公式(在 VBA 中)獲取公式。范圍(“A1”)。值(在 VBA 中)獲取值。

因此,請嘗試在蟒蛇中使用 .公式

(感謝:從單元格中獲取公式 - VBA ...如果這有效)


查看完整回答
反對 回復 2022-09-27
?
四季花海

TA貢獻1811條經驗 獲得超5個贊

只是想在這里添加我自己的解決方案。

我所做的是循環訪問列并應用“cell.number_format= '0%',這會將您的單元格值轉換為百分比。

for col in ws.iter_cols(min_row=1, min_col=2, max_row=250, max_col=250): 
   for cell in col:
        cell.number_format = '0%'

更多信息可以在這里找到: https://openpyxl.readthedocs.io/en/stable/_modules/openpyxl/styles/numbers.html


查看完整回答
反對 回復 2022-09-27
  • 2 回答
  • 0 關注
  • 148 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號