python - Use openpyxl to edit a Excel2007 file (.xlsx) without changing its own styles? -
i have .xlsx file edit, found openpyxl manipulate excel 2007 files. want change value in cells , leave other settings unchanged.
but after went through documentation, cannot find examples edit existing file. demostrated reading .xlsx file , writing new one.
i tried below way edit existing file, after saved it, styles in file has been removed( fonts, colors):
from openpyxl.reader.excel import load_workbook wb=load_workbook(r'd:\foo1.xlsx') ws=wb.get_sheet_by_name('bar') ws.cell('a1').value= 'new_value' # save workbook new file finish editing # style settings has been removed (such font, color) in new file wb.save(r'd:\foo2.xlsx')
now openpyxl cannot handle styles enough, tried using pywin32 com , got solution. here python-excel-mini-cookbook use pywin32 com excel
Comments
Post a Comment