2015-06-11 106 views
1
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") 

有谁知道我为什么会出现此错误?我从字面上从包的演示网站复制了这段代码,并且出现了这个错误。xlwt错误消息IOError:[Errno 13] Permission denied:'python_spreadsheet.xls'

IO错误:[错误13]许可被拒绝:“python_spreadsheet.xls”

+0

你不必写该文件夹中的文件的权限。 尝试在'book.save()'中指定您有权写入的路径。或者检查文件是否打开。 – Vaulstein

回答

1

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

0

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

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

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')