使用 win32com.client 模块在 Python 中将 .XLSX 转换为 .XLS [英] Converting .XLSX to .XLS in Python with win32com.client module

查看:43
本文介绍了使用 win32com.client 模块在 Python 中将 .XLSX 转换为 .XLS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找到一种将许多文件从 .xlsx 转换为 .xls 的方法,并且一直在尝试使用带有 win32com.client 模块的 Python:

<块引用>

导入 win32com.clientxl = 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.退出()

我没有错误消息,但转换后的文件没有显示在我为其设置的文件夹中.不知道我做错了什么.

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

谢谢!

解决方案

我不知道哪里出了问题,你的代码对我有用.我使用了一个示例文件并对其进行了测试,它有效.或者尝试在 SaveAs 命令前后插入 print("Checking") 和 input() 来检查是否执行了另存为命令.

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:

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

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.

这篇关于使用 win32com.client 模块在 Python 中将 .XLSX 转换为 .XLS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆