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

Blanks in Excel cells are always parsed into null values when .preferNullOverDefault(true) is used #289

Closed
OliverMobIT opened this issue Jul 21, 2023 · 2 comments

Comments

@OliverMobIT
Copy link

OliverMobIT commented Jul 21, 2023

Hello,

I am using your library to parse Excel files. Currently, I am facing an issue when I try to parse Excel cells that only contain blanks. When I use .preferNullOverDefault(true) I always get null values except when I leave that cell empty / unedited in which case I get an empty string.
For some cases this is fine. For example, some of the attributes of my parsed object are nullable. However, some of the attributes of my parsed object are non-nullable since I am working with Kotlin. I don't want these to be null but an empty string, because I want to validate with isBlank(), which can only be used with non-nullable strings. So when I call Poiji.fromExcel(file, ExampleEntry::class.java, getParsingOptions(XLS_EXAMPLE_SHEET_NAME, 2, 2)) these attributes also become null, which causes in error in my application.

Here are my parsing options, that I provide to fromExcel():

private fun getParsingOptions(
        sheetName: String,
        skipNumber: Int = 1,
        headerCount: Int = 0,
        limit: Int? = null
    ): PoijiOptions {
        val builder = PoijiOptions.PoijiOptionsBuilder.settings()
            .sheetName(sheetName)
            .skip(skipNumber)
            .headerCount(headerCount)
            .preferNullOverDefault(true)
            .trimCellValue(true)

        if (limit != null) builder.limit(limit)

        return builder.build()
    }

Do you have any suggestions for a proper solution?

Thanks in advance!

@github-actions
Copy link

Thank you for contributing to Poiji! Feel free to create a PR If you want to contribute directly :)

@ozlerhakan
Copy link
Owner

Hi @OliverMobIT,

I think you could create a customizable Casting class that can make nullable strings to non-nullable ones. Please look into some related tasks and discussions about this context:

  1. Cast Specific Cells / Ignore Some Cells while Custom Casting #287
  2. Custom casting example #252
  3. https://github.com/ozlerhakan/poiji#custom-casting-implementation

I hope those references can help you fix the problem. Please let me know if you have further questions.

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