开发者

How to use Python's win32com to "save as" an Excel file?

开发者 https://www.devze.com 2022-12-11 08:10 出处:网络
I have a small Python code to open an Excel file. Now I want to "Save As" with a different name but 开发者_StackOverflowsame format.

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


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()
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号