xlwt error message IOError: [Errno 13] Permission denied: 'python_spreadsheet.xls'

5.6k views Asked by At
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")

Does anyone know why I am getting this error? I literally just copied this code from the package's demo website and I got this error.

IOError: [Errno 13] Permission denied: 'python_spreadsheet.xls'

3

There are 3 answers

1
jmcnamara On

On Windows you get that error if the file is open in Excel.

On Linux you will get that error if you don't have permissions to write to the output directory or file.

0
Rahul Gupta On

Most likely, you don't have the permissions to write a file in that particular folder. Check if you have permissions to write in that particular folder.
Also, defining an absolute path for the file might help.

0
Jaskaran Singh On

Try This solution:

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