0
我想寫大量的數據到現有的Excel中。我參考了以下鏈接並驗證了寫入功能。 How to write to an existing excel file without breaking formulas with openpyxl? 但是,此功能重寫了我的單元格格式。例如,我的目標excel有所有表格的單元格邊框。但新寫入的行在空白背景(無單元格邊框)中。此外,我已經格式化了一些單元格爲'Currency',但是使用openpyxl輸出Excel,所有單元格都變爲'General'格式。如何寫入現有的excel文件而不用pandas(engine = openpyxl)覆蓋單元格格式?
如何在不更改單元格格式的情況下寫入現有的excel文件?
謝謝大家。
代碼來設置Excel應用程序
workbook = load_workbook(OutputFile,data_only=True)
writer =pd.ExcelWriter(OutputFile,engine='openpyxl')
writer.book = workbook
writer.sheets = dict((ws.title, ws) for ws in workbook.worksheets)
代碼來寫結果到Excel
FinalGen.append(FinalGenRow1)
FinalGen.append(FinalGenRow1)
df = pd.DataFrame(FinalGen)
df.to_excel(writer,sheet_name='Test',startrow =3 ,startcol =0,index = False, header = False)
什麼是您的openpyxl版本?檢查[這個問題和答案](http://stackoverflow.com/questions/40610166/fill-in-pd-data-frame-int-existing-excel-sheet-using-openpyxl-v2-3-2).. – MaxU
這對openpyxl是可能的。請到目前爲止顯示你的代碼。已添加代碼 –
。任何幫助表示讚賞! –