Rikus
Rikus

Reputation: 188

Cant find merged cell in excel with java

I am trying to retrieve a value from a cell in excel but it is merged. I am using Java

This is what i have:

        ByteArrayInputStream bxf = new  ByteArrayInputStream(entity.getAttachment().getFile());
        Workbook wb = WorkbookFactory.create(bxf);
        Sheet sheet = wb.getSheetAt(0);
        Row cpRow = sheet.getRow(4);

Here is the example of the excel:

Red Block is a merged cell :

enter image description here

edit

I am using apache.poi library

Upvotes: 1

Views: 227

Answers (1)

Tinus Jackson
Tinus Jackson

Reputation: 3663

Reason why you getting a null pointer are that the value you are looking at currently is the actual row 5 on sheet.

As stated by @Berger in the comment the 'getRow is 0 based'

Use getRow(3) instead.

Please see https://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFRow.html

aswell as

it states https://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFSheet.html

HSSFRow getRow(int rowIndex) Returns the logical row (not physical) 0-based.

Upvotes: 1

Related Questions