Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

openpyxl changes format after load file and save back

Nigel H
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 11, 2018

How can I retain all formatting and images in and existing Excel file, when using OpenPyxl to modifiy?

Running this script on an existing Excel (Office 365 Version 1811) .xlsx data file has removed all images and merged cells.

import openpyxl

template = "Reporter_R2.xlsx"
wb = openpyxl.load_workbook(template)

sheets = wb.sheetnames

header_sht = wb['Sheet1']
result_sht = wb['Pre-Test Data']
header_sht.cell(row=1, column=1, value = "{}".format('StartOfTest'))
wb.save(template)

The 'template' file I am reading and writing has several sheets with lots of formatting so it will be helpful to retain the original formatting after making small changes with openpyxl.

I am using Python 3.6.7 with openpyxl 2.5.9.

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events