IndexError while load_workbook() a just-save()ed xlsx
Created originally on Bitbucket by smdsbz (Xiaoguang Zhu)
using Python_3.5.2 with openpyxl_2.4.2 (without PIL/Pillow, only deal with texts) on Ubuntu_16.04
I get an IndexError while tempting to open a just-created xlsx which WAS 6.7KB. I open it (with WPS Spreadsheets), ctrl-s and exit (yes, I did nothing but ctrl-s), the file is now 8.9KB, and now I can load_workbook() it without getting an error.
(cells contain Chinese but I don't think that's where the problem lies...)
lines I use to generate the xlsx:
#!python
def newFile(title="测试测试", depart="其他", *, date=str(datetime.now())):
''' derive a new .xlsx from ./score-sheets/template.xlsx '''
filename = title + ' - ' + date + '.xlsx'
dst = os.path.join(FOLDER, filename)
try:
wb = load_workbook(os.path.join(FOLDER, 'template.xlsx'))
except IOError:
return 0
else:
ws = wb.get_sheet_by_name(wb.get_sheet_names()[0])
ws.title = title
ws['B1'].value, ws['F1'].value, ws['J1'].value = title, depart, date
with sqlite3.connect(DATABASE) as database:
cursor = database.execute("select name from test where depart = '%s'" % depart)
names = cursor.fetchall()
for i in range(len(names)):
ws['A'+str(i+3)].value = names[i][0]
wb.save(dst)
return 1
debug page created by Flask
indicates something related to the stylesheet which really confuses me (might be helpful):
sending you the 6.7KB xlsx...
Attachments: aaaaaaa_-_3_February__2017.xlsxtemplate.xlsx