Python Forum
copy/pasting in excel WHILE keep file format - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: copy/pasting in excel WHILE keep file format (/thread-27834.html)



copy/pasting in excel WHILE keep file format - zarize - Jun-23-2020

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