python的代码保存到文档中 打不开怎么办_为什么我不能从Python代码中“另存为”Excel文件?...

作者在使用自定义的Python ExcelDocument类时,遇到在调用saveAs方法保存Excel文件时出现错误,错误信息提示文件无法访问。文章将探讨问题原因并可能的解决方案,涉及Windows文件路径和Excel资源冲突问题。
摘要由CSDN通过智能技术生成

我有一个PythonExcelDocument类,它为读取/写入/格式化Excel文件提供了基本的方便方法,而且我在看似简单的Python代码中遇到了一个奇怪的错误。我有一个save andsaveAs方法:def save(self):

''' Save the file '''

self.workbook.Save()

def saveAs(self, newFileName):

''' Save the file as a new file with a different name '''

self.workbook.SaveAs(newFileName)

save方法工作得很好,但是当我试图调用saveAs方法-myExcelObject.saveAs("C:/test.xlsx")时,会得到以下错误:Traceback (most recent call last):

File "C:\workspace\Utilities\src\util\excel.py", line 201, in

excel.saveAs("C:/test.xlx")

File "C:\workspace\Utilities\src\util\excel.py", line 185, in saveAs

self.workbook.SaveAs(newFileName)

File "", line 7, in SaveAs

pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'Microsoft Office Excel', u"Microsoft Office Excel cannot access the file 'C:\\//8CBD2000'. There are several possible reasons:\n\n\u2022 The file name or path does not exist.\n\u2022 The file is being used by another program.\n\u2022 The workbook you are trying to save has the same name as a currently open workbook.", u'C:\\Program Files\\Microsoft Office\\Office12\\1033\\XLMAIN11.CHM', 0, -2146827284), None)

有人能解释发生了什么事吗?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值