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

Save xlsx file from gsheets alters file #749

Closed
nicosafull opened this issue Aug 7, 2024 · 2 comments
Closed

Save xlsx file from gsheets alters file #749

nicosafull opened this issue Aug 7, 2024 · 2 comments

Comments

@nicosafull
Copy link

nicosafull commented Aug 7, 2024

Hello,

I am experiencing an issue with the xlnt library when trying to read spreadsheets that have been saved from Google Sheets. When I open a spreadsheet with MS Excel and save it as an xlsx file, the xlnt library is able to parse and save the file correctly. However, if I open the same file with Google Sheets and save it again (keeping the xlsx format), the xlnt library no longer "understands" the empty/null cells.

Here is a code snippet that demonstrates the issue:

wb.load(DatFileNames.As_Ansi());

if (!wb.contains("Functions"))
    return FALSE;

//-- Find the sheet.
auto ws = wb.sheet_by_title("Functions");

//-- Get the number of records excluding header.
auto rows = ws.rows();
m_NumFunctions = rows.length() - 1;

In this case, m_NumFunctions returns 53 when the file is saved with MS Excel, which is the correct number of rows in the spreadsheet. However, when the file is saved with Google Sheets then m_NumFunctions returns 999.

When I iterate through the rows, I encounter another issue. Here is the code snippet:

for (size_t i = 0; i < m_NumFunctions; i++)
{
    size_t rowIndex = i + 2; // 2 as offset because we must consider Excel is not zero based and then because we want to skip first row as it's the header
    CommandID = rows.cell(L_String("A%d", rowIndex).As_Ansi()).value<int>();
}

In this case, CommandID on the actual last row is 53, which is correct. However, on the following iteration (that only happens when file is saved on Google Sheets as on MS Excel it just finishes because it read the legth properly) CommandID returns "0" (zero), even though there is no actual zero in the spreadsheet. I have seen other users struggling with similar issues when using Google Sheets, as it seems to be defaulting a zero on cells that it cannot properly set.

I am not sure how to make the xlnt library "aware" that "0" is not a legitimate value but an actual end-of-line or terminator. I would appreciate any help or suggestions on how to resolve this issue.

Thank you.

@m7913d
Copy link

m7913d commented Aug 15, 2024

As discussed in issue #748, this repo has been unmaintained for several years.
In order to continue this great project started by tfussell, we have created a new repo to support further development by the community.
Feel free to participate in this community effort by submitting issues and PR to this new community-driven repo.

@nicosafull
Copy link
Author

As discussed in issue #748, this repo has been unmaintained for several years. In order to continue this great project started by tfussell, we have created a new repo to support further development by the community. Feel free to participate in this community effort by submitting issues and PR to this new community-driven repo.

thank you very much

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

2 participants