python - How to determine last row populated for a certain column in xlsxwriter? -
i want insert 'a3' in ws.write method call automatically determining 'a3' last row value in column 'a'. method in xlxswriter below sums values in cell a1 thru a3 , prints sum in row 4, column a. how can insert 'a3' automatically using xlsxriter?
ws.write(4, 0, '=sum(a1:a3)')
xlsxwriter doesn't provide user tools track data written worksheet since can done more easily, , user's requirements, within python program.
if writing data worksheet, within loop or similar, can track maximum row number used , update formula accordingly.
like this:
import xlsxwriter workbook = xlsxwriter.workbook('file.xlsx') worksheet = workbook.add_worksheet() data = [13, 24, 15] row_num, value in enumerate(data): worksheet.write(row_num, 0, value) row_num += 1 worksheet.write(row_num, 0, '=sum(a1:a{})'.format(row_num)) workbook.close()
output:
Comments
Post a Comment