2015-06-11 108 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')