错误提示:
>>> wb.save("C:\\Users\\lk\\Desktop\\我的Excel.xlsx")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\lk\AppData\Local\Programs\Python\Python37\lib\site-packages\openpyxl\workbook\workbook.py", line 407, in save
save_workbook(self, filename)
File "C:\Users\lk\AppData\Local\Programs\Python\Python37\lib\site-packages\openpyxl\writer\excel.py", line 291, in save_workbook
archive = ZipFile(filename, 'w', ZIP_DEFLATED, allowZip64=True)
File "C:\Users\lk\AppData\Local\Programs\Python\Python37\lib\zipfile.py", line 1207, in __init__
self.fp = io.open(file, filemode)
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\lk\\Desktop\\我的Excel.xlsx'
>>> wb.save("C:\\Users\\lk\\Desktop\\我的Excel.xlsx")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\lk\AppData\Local\Programs\Python\Python37\lib\site-packages\openpyxl\workbook\workbook.py", line 407, in save
save_workbook(self, filename)
File "C:\Users\lk\AppData\Local\Programs\Python\Python37\lib\site-packages\openpyxl\writer\excel.py", line 291, in save_workbook
archive = ZipFile(filename, 'w', ZIP_DEFLATED, allowZip64=True)
File "C:\Users\lk\AppData\Local\Programs\Python\Python37\lib\zipfile.py", line 1207, in __init__
self.fp = io.open(file, filemode)
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\lk\\Desktop\\我的Excel.xlsx'
错误原因:
对应表格被其他软件打开,python在去保存文件的时候会提示这个错误,只需要把提示的这个表格给他关闭,然后在执行save方法的时候就可以保存成功了!