I have two excel files, the input file in xlsx and the output file in xlsm. With the below code i am creating a list of unique values of names. In the loop trying to filter the name with each unique value and trying to write the data xlsm format with separate excel tab for each name.
import pandas as pd
names = []
read_file = pd.read_excel('input_file.xlsx')
read_file['DATE'] = read_file['DATE'].dt.strftime('%d/%m/%y')
names = read_file['Name'].unique().astype(str) # gets unique values and stores in str
for n in names:
data = read_file[(read_file['Name'] == n)]
with pd.ExcelWriter('output_file.xlsm',engine='openpyxl',mode='a',if_sheet_exists='replace') as writer:
data.to_excel(writer,sheet_name = n,index=False, startrow=0, header=True)
I am not getting any error while running this code, but the xlsm file/output_file is getting corrupted when trying to open this file.
When I used the same code for xlsx format, this code is working fine.
Any suggestion on where i am going wrong?