Python_报错:
D:Python36python.exe D:/test_excel/excel_001.py
Traceback (most recent call last):
File "D:/test_excel/excel_001.py", line 14, in <module>
wb.save("e:\sample.xlsx")
File "D:Python36libsite-packagesopenpyxlworkbookworkbook.py", line 367, in save
save_workbook(self, filename)
File "D:Python36libsite-packagesopenpyxlwriterexcel.py", line 282, in save_workbook
archive = ZipFile(filename, 'w', ZIP_DEFLATED, allowZip64=True)
File "D:Python36libzipfile.py", line 1090, in __init__
self.fp = io.open(file, filemode)
PermissionError: [Errno 13] Permission denied: 'e:\sample.xlsx'
源码:
import locale from openpyxl import Workbook import datetime import time import locale wb = Workbook() ws = wb.active ws['A2']= datetime.datetime.now()#写入一个当前时间 #写入一个自定义的时间格式 locale.setlocale(locale.LC_CTYPE,'chinese') ws['A3'] = time.strftime("%Y年%m月%d日 %H时%M分%S秒",time.localtime()) # Save the file wb.save("e:\sample.xlsx")
原因:excel文件是打开的,资源被占用,在进行操作时,关闭写入的文件即可
运行结果: