Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Poi update xls file

I am using Apache Poi in an Android application, but I have a problem with the update of xls file.

To change the value of a cell where there is already a value I have no problem, but I have a null pointer exeption when I change the value of empty cells.

I use the method setCellValue.

like image 366
user3244162 Avatar asked Feb 23 '26 09:02

user3244162


1 Answers

You may need to create the cell before you change the value of it. If a cell has no value it 'doesn't exist' so to speak and so you need to create it and then set it's value. You could try using the getCell() with mising rowPolicy to try and obtain a cell if their isn't currently one, like so:

myRow.getCell(7, Row.CREATE_NULL_AS_BLANK);//Should create cell if it is currently blank

Once you have the cell, try setting it's value as you have been doing.

Alternatively, try checking beforehand if you have a cell, e.g

if (myCell ==null) {
//Create cell code
Cell cell = row.createCell(0);
}

Good luck!

like image 138
Levenal Avatar answered Feb 25 '26 01:02

Levenal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!