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

mandatoryCell doesn't do anything #332

Open
Dzeri96 opened this issue Mar 6, 2025 · 1 comment
Open

mandatoryCell doesn't do anything #332

Dzeri96 opened this issue Mar 6, 2025 · 1 comment

Comments

@Dzeri96
Copy link

Dzeri96 commented Mar 6, 2025

Maybe I misunderstood something, but if I set mandatoryCell to true in the ExcelCellName annotation, it does not seem to throw an error when it comes across an empty cell. Instead, I just get null in the annotated field. Is this supposed to happen? If so, how could I get a CastingError to let the user know that a mandatory value is missing?

For reference, I'm using an XLSX file stream and POIJI 4.6.

Edit: After further digging through the source code, it seems like the mandatoryCell value is only checked in the HSSFUnmarshaler, which gets used for .xsl files or Sheets. I was able to trigger the PoijiMultiRowException by passing the Sheet directly, but I realized it does not really help the user in any way. I would ideally need just the row and column of the cell like with the CastingError, and not a total crash of the import process, but I guess for that you'd need to rewrite a large part of the codebase...

Edit 2: I found a hacky way around this: By setting the missing cell policy to CREATE_NULL_AS_BLANK in the worksheet before passing the Sheet, I can catch empty strings in my custom Casting and create custom errors there. This only works because all of my cells are mandatory though.

@ozlerhakan
Copy link
Owner

Hi @Dzeri96 ,

As the doc states, the mandatoryCell feature is only supported in XLS files.

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