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

PoiExcelUtil.getExcelDataAsMap() returns NullPointerException when there is no content in cell #386

Closed
2 of 6 tasks
WendyZ123 opened this issue Oct 19, 2021 · 2 comments
Closed
2 of 6 tasks
Assignees
Milestone

Comments

@WendyZ123
Copy link

QAF Version

3.0.1b

Steps To Reproduce

1. prepare an excel sheet called "test" with a table like :
| Name | Age |
| Lilly | 18 |
| Jane | |
| Tom | 19 |
2. call PoiExcelUtil.getExcelDataAsMap(filePath, test); (test is sheetName)
3. run it

Expected behavior

read data from an excel file and return it as an object[][].

Actual behavior

return NullPointerException

Is the issue reproducible on runner?

Yes

  • QAS
  • Maven
  • Gradle
  • Ant
  • Eclipse
  • Intellij IDEA

Test case sample

Read data from the file and verify its size is not zero.

@cjayswal
Copy link
Contributor

It worked as Expected for me. No Key-value / null for column, where col is empty, which is expected behavior.

@WendyZ123
Copy link
Author

I think exception comes from this method:
+++++++++++++++++++++++++++++++
public static Object getCellContent(Cell cell) {
if (cell != null) {
FormulaEvaluator evaluator = cell.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator();
CellValue cellValue = evaluator.evaluate(cell);
...}}
+++++++++++++++++++++++++++++++
cellValue will be null if there is no content in cell. When we call cellValue.getCellType() later, It will throw NullPointerException.

But getCellContentAsString() method has handled it.
+++++++++++++++++++++++++++++++
public static String getCellContentAsString(Cell cell) {
if (cell != null) {
FormulaEvaluator evaluator = cell.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator();
CellValue cellValue = evaluator.evaluate(cell);
if (cellValue == null) {
return "";
} else {
...}..}
+++++++++++++++++++++++++++++++

I'm thinking if there is no value in cell, shall we handle it and return null or empty string?

@cjayswal cjayswal added this to the 3.1.0 milestone Dec 30, 2021
cjayswal added a commit that referenced this issue Jan 2, 2022
- used same implementation for xls and xlsx
- removed old implementation ExcelUtil
- #342 for cell with string (Text or @) format, considering empty cell
value as empty string. Null for others including no format (General)

Related to #386, #339, #269
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants