Free Support Forum -

Getting a Null Pointer when calling cells.applyRowStyle(rowIndex- getHeaderStyle()- flag);


I need to set the background color of the entire row
When I do this:
StyleFlag flag = new StyleFlag();
cells.applyRowStyle(rowIndex, getHeaderStyle(), flag);

I get a null pointer exception on the applyRowStyle line. Any ideas what I am doing wrong?


Hi Nathan,

Thank you for contacting Aspose support.

I have used the following piece of code against the latest version of Aspose.Cells for Java 8.5.0 to verify your presented scenario. Please note, I am unable to replicate the said exception, in fact the style was applied correctly to the specified row.

Please give a try to the following code on your end. In case the problem persists, please provide us your input spreadsheet along with your complete code (most preferably a sample application) for further investigation.


Workbook sourcebook = new Workbook(“sample.xlsx”);
Worksheet sheet = sourcebook.getWorksheets().get(0);
Cells cells = sheet.getCells();
Style style = sourcebook.createStyle();
StyleFlag flag = new StyleFlag();
cells.applyRowStyle(0, style, flag);“D:/output.xlsx”);