8000 new feature: name a cell range and few minor fixes by dorssar · Pull Request #150 · dhatim/fastexcel · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

new feature: name a cell range and few minor fixes #150

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

Merged
merged 14 commits into from
Mar 10, 2021

Conversation

dorssar
Copy link
Contributor
@dorssar dorssar commented Feb 10, 2021

The new functionality of naming a Range can be used like this:

ws.range(0, 0, 0, 10).setName("header);

IMPORTANT: name of a cell range can only contain letters, numbers and underscore.
(This is an external limitation - LibreOffice Calc also doesn't allow any other characters.)

Besides named ranges, there's a fix for LibreOffice Calc to make it recognize the autofilter if it's been set in the generated XLSX document.
LibreOffice requires a specifically named range "_xlnm._FilterDatabase" to recognize the autofilter in generated documents.
This bug has been reported multiple times to bugzilla, however, many years have passed and no one had changed the way it works.

This way, by defining a named range, fastexcel will be able to generate documents with autofilter that will be opened properly in LibreOffice Calc.
The oddly named range will, ofcourse, also exist when opened in Google Sheets and Excel, but it will just be an extra defined named range.

There were a few minor mistakes from my side earlier, where the localSheetId was hardcoded to 0 - now the worksheet index is properly assigned.
Also, when sheetname had a space or another non-alphabetical characted, the definitions were not correctly written to xlsx - sheetname needs to be surrounded with ' or - in other words - '

.collect(Collectors.joining(","));

w.append("<definedNames>");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If defineName and namesRanges are empty then will never be closed.

Copy link
Contributor Author
@dorssar dorssar Feb 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you overlooked (it's being closed on line 254 either way).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if both defineName and namedRanges are not empty, then it will be closed twice?

Copy link
Contributor Author
@dorssar dorssar Feb 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be opened and then closed only once, but there are conditional <definedName> tags inside of this <definedNames> tag.

Copy link
Contributor Author
@dorssar dorssar Feb 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they are empty - we'll have <definedNames></definedNames>, otherwise if any of them are non-empty we will have

<definedNames>
    <definedName>....sth...</definedName>
    <definedName>....sth2...</definedName>
</definedNames>

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. I see it now. I misstook line 221 as </definedNames>. Nevertheless I would be good to cover this part of code in a test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, will try to do that. Where should I put this test?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can put it in a new class in src/test/java

Copy link
Contributor Author
@dorssar dorssar Mar 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I put it into PoiCompatibilityTest.java ? I guess all of the existing similar tests are there ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Please include a test that verifies (for example using Apache POI) that a worksheet with a named range is valid.

Done!

Copy link
Collaborator
@rzymek rzymek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please include a test that verifies (for example using Apache POI) that a worksheet with a named range is valid.

@dorssar dorssar requested a review from rzymek March 10, 2021 14:57
@rzymek rzymek merged commit 47ff169 into dhatim:master Mar 10, 2021
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

Successfully merging this pull request may close these issues.

2 participants
0