Crash when writing an empty row in Excel sheet

Issue #398 resolved
David Laudy
created an issue

Hello,

I have a crash when trying to write an empty row between non empty rows.

The following code snippets shows the problem.

import openpyxl
import os

workbook = openpyxl.workbook.Workbook(optimized_write=True)
sheet = workbook.create_sheet()
sheet.title = u'hello'
sheet.append(['1', '2', '3'])
sheet.append([])
sheet.append(['4', '5'])

workbook.save(os.path.join(os.getcwd(), 'test_empty_rows.xlsx'))

I am running openpyxl 2.1 with lxml.

The traceback I get is

Traceback (most recent call last):
  File "write_empty_row.py", line 9, in <module>
    sheet.append([])
  File "C:\data\workspace\pylos\openpyxl\writer\dump_lxml.py", line 132, in append
    self._max_col = max(self._max_col, col_idx)
UnboundLocalError: local variable 'col_idx' referenced before assignment

Thanks to have a look.

David

Comments (4)

  1. Log in to comment