Python Forum

Full Version: copy/pasting in excel WHILE keep file format
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys,

I would like to copy/paste some things in excel files BUT with keeping current format of the file.

The original file is in .xls and it has some macro inside of it.
While i run the code, it does the job and save it to .xlsx, however it loses completely format and macros.

What can i do to do this task and to keep the file format?

import pandas as pd

excel = pd.read_excel(PATH\Original_file.xls, header=None)
writer = pd.ExcelWriter(PATH\Test.xlsx", engine='xlsxwriter')

left_values = excel.loc[6:21, 16:22]
right_values = excel.loc[6:21, 30:36]
right_values = left_values

excel.to_excel(writer, 'sheet1', index=False, header=False)
In the attachment there is part of the original excel file