我在Windows 7上的Komodo edit 9和python3.4中使用openpyxl脚本时遇到问题。我复制了一些openpyxl代码以进行学习,但无法从Komodo中执行。我收到权限错误13。我检查了路径,并且存在python34。当我使用IDLE或命令提示符时,将运行相同的脚本。我的Komodo命令当前为:%(python3)-u%F关于什么可能导致此问题的任何想法?代码和错误包括在下面
from openpyxl import Workbook from openpyxl.compat import range from openpyxl.cell import get_column_letter wb = Workbook() dest_filename = 'empty_book.xlsx' ws1 = wb.active ws1.title = "range names" for row in range(1, 40): ws1.append(range(600)) ws2 = wb.create_sheet(title="Pi") ws2['F5'] = 3.14 ws3 = wb.create_sheet(title="Data") for row in range(10, 20): for col in range(27, 54): _ = ws3.cell(column=col, row=row, value="%s" % get_column_letter(col)) print(ws3['AA10'].value) wb.save(filename = dest_filename)
-------开始错误-----------
AA Traceback (most recent call last): File "C:\Users\PF15043\Desktop\Scripts\Ggizmo\excelReader.py", line 26, in <module> wb.save(filename = dest_filename) File "C:\Python34\lib\site-packages\openpyxl-2.3.0b1-py3.4.egg\openpyxl\workbook\workbook.py", line 254, in save save_workbook(self, filename) File "C:\Python34\lib\site-packages\openpyxl-2.3.0b1-py3.4.egg\openpyxl\writer\excel.py", line 195, in save_workbook writer.save(filename, as_template=as_template) File "C:\Python34\lib\site-packages\openpyxl-2.3.0b1-py3.4.egg\openpyxl\writer\excel.py", line 177, in save archive = ZipFile(filename, 'w', ZIP_DEFLATED, allowZip64=True) File "C:\Python34\lib\zipfile.py", line 923, in __init__ self.fp = io.open(file, modeDict[mode]) PermissionError: [Errno 13] Permission denied: 'empty_book.xlsx'
这只是来自操作系统的错误,告诉您您无权在尝试创建的文件中创建文件。您应该指定要创建的文件的完整路径。