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

Blank cells throwing null pointer exception while reading #33

Open
abhilashreddy1289 opened this issue Mar 3, 2016 · 7 comments
Open

Comments

@abhilashreddy1289
Copy link

I am using this api and rows contains blank cells causing null pointer issue. Below is the stack trace.
com.monitorjbl.xlsx.exceptions.NotSupportedException
java.lang.NullPointerException
at test.XLSXToCSVConverterStreamer.xlsx(XLSXToCSVConverterStreamer.java:67)
at test.XLSXToCSVConverterStreamer.main(XLSXToCSVConverterStreamer.java:164)

if I use Cell cell = row.getCell(i, Row.CREATE_NULL_AS_BLANK) to read empty cells as blank I am getting below issue. Kindly help me in resolving this

com.monitorjbl.xlsx.exceptions.NotSupportedException
at com.monitorjbl.xlsx.impl.StreamingRow.getCell(StreamingRow.java:108)

@andreasellervee
Copy link

I had a similar issue, I solved it like this:

Cell cell = row.getCell(i);
if (cell == null) {
cell = new StreamingCell(i, row.getRowNum());
}

this just creates a StreamingCell with null value and you can go from there.

edit// formatting (indentation does not seem to work here)

@jhhino
Copy link

jhhino commented Apr 27, 2016

@andreasellervee thank you so much for your post. It helped me a lot. I was at the same issue and I could fix it by using your solution.
I realized when we use StreamingReader and iterate cells of a row, it does not consider cells with blank value, shifting to the next cell with valid value and messing the rest of columns out.

Just to exempify, I was considering the code below:

for (Row row : reader) {
            String[] recordArray = new String[totalColumns];
            int columnSheet = 0;
            for (Cell cell : row) {
                recordArray[columnSheet] = cell.getStringCellValue();
                columnSheet++;
            }

            listRegistration.add(recordArray);
        }

than I've changed to this, in order to work well:

for (Row row : reader) {
            String[] recordArray = new String[totalColumns];
            int columnSheet = 0;
            for (int i=0; i<totalColumns; i++) {
                Cell cell = row.getCell(i);
                if (cell == null) {
                    cell = new StreamingCell(i, row.getRowNum());
                }
                recordArray[columnSheet] = cell.getStringCellValue();
                columnSheet++;
            }

            listRegistration.add(recordArray);
        }

@waxxxd
Copy link
Contributor

waxxxd commented Feb 1, 2017

Hello abhilashreddy1289

Cell cell = row.getCell(i, Row.CREATE_NULL_AS_BLANK) is now supported and resolves the issue.

Hope this is good news.

@moisesf10
Copy link

Row.CREATE_NULL_AS_BLANK not working

@waxxxd
Copy link
Contributor

waxxxd commented Jun 14, 2017

Can you confirm that you are using the latest maven version 1.1.0.

If you are please provide the sheet and code. Then we can help you.

@dlandis
Copy link

dlandis commented Feb 12, 2018

@waxxxd

Any thoughts on implementing setMissingCellPolicy:

  @Override
  public void setMissingCellPolicy(MissingCellPolicy missingCellPolicy) {
    throw new UnsupportedOperationException();
  }

on StreamingWorkbook? Then it wouldn't have to be passed in for every getCell call.

@waxxxd
Copy link
Contributor

waxxxd commented Sep 10, 2018

Hello @dlandis

I haven't really looked into the code too much. Committed the change to fix a bug I had encountered in a personal project. Have a crack at it.

rimuln referenced this issue in rimuln/excel-streaming-reader Nov 15, 2021
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

6 participants