-
-
Notifications
You must be signed in to change notification settings - Fork 134
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
Improve mandatoryCell behavior for opened sheets #311
Comments
I believe the place we should be looking at is somewhere near Cell cell = currentRow.getCell(annotationDetail.getColumn());
if (cell != null) {
...
} else if (annotationDetail.isMandatoryCell()) {
// this is never reached, since the cell is not null
throw new PoijiRowSpecificException(annotationDetail.getColumnName(), field.getName(), currentRow.getRowNum());
} I suggest adding a check if the cell is blank but mandatory before casting the value using At the moment I have a workaround using the latter option via an overridden |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hi @virtual-machinist ! Sorry I got busy with other tasks. I'm open to any suggestion based on your findings for this issue. |
@ozlerhakan same here. One thing I found was that doing |
@ozlerhakan , I've opened a PR with this change, and also added a test case based on the previous one where the cell was simply However, the test modifies XLSX files every time it's run (i.e. I see the file has been changed in git log after running tests). Can this be a problem? |
Thanks @virtual-machinist !
I'd say that we shouldn't modify an excel, do you think you can find a fix for that? |
@ozlerhakan , had a look at the problem. Apparently I forgot that I have to open the workbook in read-only mode for the tests. This was no issue when I used an Also while investigating this problem I saw a better workaround for the whole issue by using the This however cannot be done if using the The missing cell policy option looks better to me, I think we should document this for opened sheets (i.e. when using OR expose What do you think? |
Cool!
There are indeed by design different constraints between XLS and XLSX approaches. Probably, this is also one of the challenges among them. I'd choose the first option where we can have support this by default and document it explicitly. |
Did a second attempt at this. Added test cases for both XLS stream and file, and also one for opened XLSX sheet, since mandatory cell check works there as well. |
Thanks @virtual-machinist , I'll plan to merge it with a new release. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hey @virtual-machinist , I've just merged the changes, thanks a lot! |
The
mandatoryCell
feature works rather strangely:XSSFSheet
instance)The first three cases are documented, i.e. I shouldn't expect the parser to work correctly for XLSX format, however the last two aren't.
From layman's point of view there isn't too much difference between blank and missing cells, meaning nobody will re-examine if the contents of the cell were cleared together with or without formatting. Thus, it makes sense to expect the same
com.poiji.exception.PoijiMultiRowException
for both blank and missing cells in an XLS workbook that the feature applies to.Seeing that
XSSFSheet
is actually parsed the same way asHSSFSheet
usingcom.poiji.bind.mapping.SheetUnmarshaller
we can at least try to fix/improve behavior for opened sheets. XLSX files and streams use a different unmarshaller andmandatoryCell
check isn't done there in any way, i.e. adding this feature there may be out of scope for this issue.I've added test cases to my missing-cell-ignored branch. The excel files basically have the same input as the constructed sheet in
com.poiji.deserialize.MandatoryCellsExceptionTest#createDummyExcel
. The old XLS format was derived from the XLSX using thessconvert
utility.The text was updated successfully, but these errors were encountered: