简体   繁体   English

使用win32com.client模块将.XLSX转换为Python中的.XLS

[英]Converting .XLSX to .XLS in Python with win32com.client module

I am trying to find a way to convert many files from .xlsx to .xls and have been trying Python with the win32com.client module: 我试图找到一种方法将许多文件从.xlsx转换为.xls,并一直在使用win32com.client模块尝试Python:

 import win32com.client xl = win32com.client.Dispatch("Excel.Application") wb = xl.Workbooks.Open(r"C:\\Users\\Kathleen\\Desktop\\Exp 1_1\\A 1-1-1c.xlsx") wb.SaveAs(r"C:\\Users\\Kathleen\\Desktop\\Exp 1_1\\A 1-1-1c.xls", FileFormat = 56) wb.Close() xl.Quit() 

I have no error message but the converted file does not show up in the folder I have it set up for. 我没有错误消息,但转换后的文件没有显示在我设置的文件夹中。 Not sure what I am doing wrong. 不确定我做错了什么。

I have Windows 7, 64 bit and have downloaded: Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32 我有Windows 7,64位并已下载:win32上的Python 2.7.3(默认,2012年4月10日,23:24:47)[MSC v.1500 64位(AMD64)]

Thanks! 谢谢!

I am not sure what is wrong, your code works for me. 我不确定有什么问题,你的代码对我有用。 I used a sample file and tested it, it works. 我使用了一个示例文件并进行了测试,它确实有效。 Maybe try inserting print("Checking") and input() before and after the SaveAs command to check whether the save as command is executed or not. 也许尝试在SaveAs命令之前和之后插入print(“Checking”)和input()来检查是否执行了save as命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM