xlwt错误消息IOError:[Errno 13]权限被拒绝:' python_spreadsheet.xls'

时间:2015-06-11 13:15:27

标签: python python-2.7 xlwt

import xlwt

book = xlwt.Workbook(encoding="utf-8")
sheet1 = book.add_sheet("Python Sheet 1") 
sheet2 = book.add_sheet("Python Sheet 2") 
sheet3 = book.add_sheet("Python Sheet 3")
sheet1.write(0, 0, "This is the First Cell of the First Sheet") 
sheet2.write(0, 0, "This is the First Cell of the Second Sheet") 
sheet3.write(0, 0, "This is the First Cell of the Third Sheet") 
sheet2.write(1, 10, "This is written to the Second Sheet") 
sheet3.write(0, 2, "This is part of a list of information in the Third Sheet") 
sheet3.write(1, 2, "This is part of a list of information in the Third Sheet") 

book.save("python_spreadsheet.xls")

有谁知道我收到此错误的原因?我只是从包的演示网站上复制了这段代码,我收到了这个错误。

IOError:[Errno 13]权限被拒绝:' python_spreadsheet.xls'

3 个答案:

答案 0 :(得分:2)

最有可能的是,您没有权限在该特定文件夹中写入文件。检查您是否有权在该特定文件夹中书写 此外,为文件定义绝对路径可能会有所帮助。

答案 1 :(得分:1)

在Windows上,如果文件在Excel中打开,则会出现该错误。

在Linux上,如果您没有权限写入输出目录或文件,则会收到该错误。

答案 2 :(得分:0)

尝试此解决方案:

import xlwt 
wb = xlwt.Workbook('Database1.xls')
ws = wb.add_sheet('Sheet1') 
ws.write(9, 0, 11)
ws.write(9, 1, 'iii')
ws.write(9, 2, 387653)
wb.save('Database1.xls')