zoukankan      html  css  js  c++  java
  • Python_报错:PermissionError: [Errno 13] Permission denied: 'XXXXX.xlsx'

    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文件是打开的,资源被占用,在进行操作时,关闭写入的文件即可

    运行结果:

  • 相关阅读:
    SSH框架整合思想
    Spring框架
    Struts2框架
    CentOS6 设置AliNetflow 环境
    Why It is so hard to explain or show some thing
    一 hadoop 相关介绍
    test markdown 写博客
    测试使用markdonw写博客
    使用spark 计算netflow数据初探
    hbase definitive guide 笔记
  • 原文地址:https://www.cnblogs.com/rychh/p/11421317.html
Copyright © 2011-2022 走看看