Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After using xlsxioread_sheet_open, cannot use xlsxioread_sheetlist_next to get the next sheet #128

Open
xiaoyuantao opened this issue Apr 18, 2024 · 7 comments

Comments

@xiaoyuantao
Copy link

After using xlsxioread_sheet_open, cannot use xlsxioread_sheetlist_next to get the next sheet.
Here's my code. I want to go through all the sheets and print out the contents.
But the actual effect really only prints the contents of the first sheet

if ((sheetlist = xlsxioread_sheetlist_open(xlsxioread)) != NULL) 
  {
    while((sheetname = xlsxioread_sheetlist_next(sheetlist)) != NULL)
    {
      XML_Char_printf(X("%p - %s\n"),(void *)sheetname,sheetname);
      sheet = xlsxioread_sheet_open(xlsxioread, sheetname, XLSXIOREAD_SKIP_EMPTY_ROWS);
      if(sheet != NULL)
      {
          while (xlsxioread_sheet_next_row(sheet)) {
              while ((value = xlsxioread_sheet_next_cell(sheet)) != NULL) {
              XML_Char_printf(X("%s\t"), value);
              xlsxioread_free(value);
              }
              printf("\n");
          }
          xlsxioread_sheet_close(sheet);
      }
    }
    XML_Char_printf(X("AA%p - %s\n"),(void *)sheetname,sheetname);


    xlsxioread_sheetlist_close(sheetlist);
  }

image

@ReanRelay
Copy link

I have 8 worksheets and can only get 2 worksheets, for some reason, using x64 binary file, version 0.2.35

@brechtsanders
Copy link
Owner

@ReanRelay Can you share a .xlsx file with this issue so I can investigate?

@80588345
Copy link

I have 5 sheets, but get only 1 sheets. any xlxs‘ files

@brechtsanders
Copy link
Owner

Please share a .xlsx file that has this issue so I can troubleshoot.

@LeoSarog
Copy link

LeoSarog commented Feb 6, 2025

So, I had the same issue today while trying to load a .xlsx with 3 sheets using exactly the same code (while loop for all sheets and then while loop for all cells).
Here's what I noticed:

  • When I was closing the .xlsx from Microsoft Excel and the active sheet at that time was let's say the second one, after when I was trying to get the next sheet from the code I could actually reach up to the second sheet (the last active sheet before I close the .xlsx).

How I managed to make it work although I believe it's not the cleanest way:

  • Opened the .xlsx
  • Stored all the sheetnames into a vector (with the same functions for xlsxioread_sheetlist_next which is weird that I don't get NULL here for my sheets).
  • Then open the sheets in a different loop with the sheet names and get all the elements.

Note: I did experiments on the same excel with the version of @xiaoyuantao (as this was my initial code version) and with the code that I am describing here and the workaround parsed correctly all the sheets, so I don't think that necessarily the problem is the .xlsx.

Hope this helps!

@brechtsanders
Copy link
Owner

Can you attach the file and some minimal code so I can reproduce and debug?

@LeoSarog
Copy link

LeoSarog commented Feb 7, 2025

@brechtsanders Sure!
Sorry for not sending the code in .hpp but for some reason github rejects my upload because of the extension (Don't know why?).

The only dependencies that I have here besides STL is spdlog which can easily be removed if you just comment all the logging.

Files:
Dummy.xlsx
not_working_version.txt
working_version.txt

Hope that you can reproduce on your side!
Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants