Reputation: 725
I am looking to write a string to a cell using Xlsxwriter, however, it seems that I can only write to a specific cell in the following formats:
worksheet.write(0, 0, 'I like pie')
worksheet.write('A1', 'I like pie')
I am first writing a dataframe to the excel worksheet and then adding a footer at the bottom ('I like pie'). I would like the footer to be written in the cell below the the last line of the dataframe without manually telling python what exact cell to write to.
Any ideas? Maybe an if statement?
Upvotes: 2
Views: 817
Reputation: 5410
Use df.shape
to get the number of rows for your dataframe, then use this number to specify the row for your footer:
nrows = df.shape[0]
worksheet.write(nrows, 0, 'I like pie')
# or: worksheet.write('A{}'.format(nrows+1), 'I like pie')
Upvotes: 3