1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > python另存为excel_为什么不能从python代码中“另存为”Excel文件?

python另存为excel_为什么不能从python代码中“另存为”Excel文件?

时间:2021-05-11 21:06:06

相关推荐

python另存为excel_为什么不能从python代码中“另存为”Excel文件?

我有一条蟒蛇

ExcelDocument

类,它为读取/写入/格式化Excel文件提供了基本的方便方法,而我在看似简单的Python代码中遇到了一个奇怪的错误。我有一个储蓄和

saveAs

方法:

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方法非常有效,但是当我尝试调用

萨维斯

方法-

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

_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\u The file name or path does not exist.\n\u The file is being used by another program.\n\u 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)

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。