RangeByName iteration fails on empty/null cells in excel

Hi,

We have an excel sheet having cells with userdefined names. We are using RangeByName along with the iterator to activate/set the values in these cells. This is working perfectly fine when we are trying to retrieve cells having values(even blanks).

But, when we try to access a empty cell using its defined name, we are facing a null pointer exception.

I have attached a sample code where we have recreated this issue.Can you please let us know the solution for this or if there is any other way to do this ?

Do let us know if you need any additional information

Thanks,

AsposeEvaluation

Hi,


Well, yes, you cannot implement iterator for the empty named range, the cells would not be initialized. I think you may try the following sample code instead:
e.g
Sample code:

for(int i = r1.getFirstRow(); i<r1.getRowCount(); i++)
{
for(int j = r1.getFirstColumn(); j<r1.getColumnCount(); j++)
{
cell1 = r1.getWorksheet().getCells().get(i,j);
System.out.println(cell1.getName());


}
}

Hope, this helps a bit.

Thank you.

Hi Amjad,

Thank you for this workaround. We are able to get the correct values now.

Hi,


Good to know that it figures out your issue now. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.

Thank you.