Blanks in Excel cells are always parsed into null values when .preferNullOverDefault(true) is used
OliverMobIT opened this issue · comments
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!
Thank you for contributing to Poiji! Feel free to create a PR If you want to contribute directly :)
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:
I hope those references can help you fix the problem. Please let me know if you have further questions.