Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use python win32com to save as excel file

I have a small Python code to open an Excel file. Now I want to "Save As" with a different name but same format. How do I do that?

like image 714
fk. Avatar asked Nov 14 '22 14:11

fk.


1 Answers

Just use the SaveAs method:

import win32com.client 

office = win32com.client.Dispatch("Excel.Application") 
wb = office.Workbooks.Open("C:/FileName.xlsx") 
wb.SaveAs(Filename="C:\\NewFileName.xlsx")
wb.Close()
office.Quit()
like image 86
EkaterinaSS Avatar answered Dec 18 '22 05:12

EkaterinaSS