jmcnamara / XlsxWriter

A Python module for creating Excel XLSX files.
https://xlsxwriter.readthedocs.io
BSD 2-Clause "Simplified" License
3.66k stars 631 forks source link

Bug: previous_row does not hold correctly the number of the last line where data is written #1090

Closed WSF-SEO-AM closed 2 months ago

WSF-SEO-AM commented 2 months ago

Current behavior

I've to admit that this is not a native approach based on the configuration, but traces in the code suggest that property to store that value. However, by the time _write_single_row is invoked (and apparently almost all methods reach that function), the self.previous_row is reset to 0 unless the row number is passed as an external argument.

Expected behavior

Previous_row to hold the number of the last line where data were written.

Sample code to reproduce

import xlsxwriter

workbook = xlsxwriter.Workbook('hello.xlsx')
worksheet = workbook.add_worksheet()

worksheet.write('A1', 'Hello world')
print(worksheet.previous_row)
workbook.close()

Environment

- XlsxWriter version:
- Python version:
- Excel version:
- OS:

Any other information

No response

OpenOffice and LibreOffice users

jmcnamara commented 2 months ago

The worksheet.previous_row property is an internal property and shouldn't be accessed by the end user. In fact it generally doesn't contain useful information, as you've seen.

Instead the user should track the last row written themselves.