-
Notifications
You must be signed in to change notification settings - Fork 62
fix xls sheet name length #7901
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
Conversation
That we can test it in isolation.
And replace the last 3 chars with random alphanumeric characters on collision. This also fixes the "duplicate sheet" error if 2 periods have the same name.
|
|
||
| const workbook = toWorkbook(sheets) | ||
|
|
||
| expect(workbook.SheetNames).toEqual([sheetName.slice(0, 31)]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are plus ou moin testing that slice does what it does, so maybe use 'a'.repeat(31)?
| expect(workbook.SheetNames).toEqual([sheetName.slice(0, 31)]) | ||
| }) | ||
|
|
||
| it('does not overwrite sheets when shortening them makes them not unique anymore', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tripped over this test name because I assumed overwrite means changing the sheet name, but you mean it doesn't replace the first one with the same (resulting) name. Maybe "does not drop sheets ..."?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not dropping, its replacing the pointer in the map. I would call that overwriting, but i am open for better formulations.
| const validSheetName = sheetName.replaceAll(/[?*[\]/\\:]/g, '') | ||
| let slicedSheetName = validSheetName.slice(0, 31) | ||
| if (workbook.SheetNames.includes(slicedSheetName)) { | ||
| slicedSheetName = validSheetName.slice(0, 28) + randomString(3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you using a random string here?
Wouldn't a simple increment be more understandable?
Like:
MeinLangerPeriodeNam001
MeinLangerPeriodeNam002
...
|
I considered 4 possible fixes:
We can pick our poison. I picked number 4. |
frontend: extract method toWorkbook in useMaterialViewHelper.js
That we can test it in isolation.
frontend: trim sheetNames to 31 chars in useMaterialViewHelper.js
And replace the last 3 chars with random alphanumeric characters
on collision.
This also fixes the "duplicate sheet" error if 2 periods have the same name.
Closes: #7184