4

does anyone know how to count the number of rows on an Excel worksheet using xlsxwriter? I have looked for a method similar to XLRD's worksheet.nrows in xlsxwriter but have not been able to find one. I had orginally tried to use both xlsxwriter and xlrd in a script but I have errors due to what I think is a problem with both xlsxwriter and xlrd trying to open the same file at the same time. I can attach the code if that would help. Thank you very much in advance!

1
  • What are the errors you get ? May 29, 2014 at 15:54

1 Answer 1

6

xlsxwriter does not support reading from a workbook. It is designed to create excel workbooks.

From their site: https://xlsxwriter.readthedocs.org/en/latest/introduction.html

It cannot read or modify existing Excel XLSX files.

3
  • Hi, thank you. That would explain why I could not find anything on it. Do you have any ideas you could create/write a new Excel file with with xlsxwriter but before you close the xlsxwriter document use xlrd to open the document to read the number of rows? I keep getting an error in which the xlrd reference to the Excel file believes the file is not there, even though it is. Thank you. May 29, 2014 at 16:57
  • @user3688163 If you haven't closed the writer, there is no guarantee that your file has been saved to disk. Indeed, if I sleep for 5 seconds after I finish writing and before reading, the book is not there.
    – MxLDevs
    May 29, 2014 at 17:21
  • 3
    It's not clear what you're trying to do here - if you're trying to find out how many rows are in the spreadsheet you're creating with xlwt, you can check the last_used_row attribute on the worksheet object. But it seems odd that you would have to do so, given that you have to set the row number when writing to the spreadsheet in the first place. May 29, 2014 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.