Free Support Forum - aspose.com

Retrieved style error

In my java application, I have a method for creating a style, which does the following:

Style newStyle = workbook.createStyle();

System.out.println("Name: " + newStyle.getName() + ", Font Name: " + newStyle.getFont().getName() + ", Size: " + newStyle.getFont().getSize());

newStyle.setName(styleName);

Font font = new Font();
font.setName(“Verdana”);
font.setSize(fontSize);
font.setBold(bold);
font.setItalic(italic);

newStyle.setFont(font);

System.out.println("Name: " + newStyle.getName() + ", Font Name: " + newStyle.getFont().getName() + ", Size: " + newStyle.getFont().getSize());

and the debug print outs from that correctly come out as:
Name: null, Font Name: Arial, Size: 10
Name: Central Idea, Font Name: Verdana, Size: 15

However, in another method (that is called after the previous method) the formatting seems to be lost. This is the second method:

Row row = cells.getRow(rowNumber);
Cell cell = row.getCell(columnNumber);

Style[] availableStyles = workbook.getNamedStyles();
Style style = workbook.getNamedStyle(styleName);
System.out.println("Name: " + style.getName() + ", Font Name: " + style.getFont().getName() + ", Size: " + style.getFont().getSize());

boolean appliedStyle = false;

for (int i = 0; i < availableStyles.length; i++) {

if (styleName.equals(availableStyles[i].getName())) {
Style toSet = availableStyles[i];
System.out.println("Name: " + toSet.getName() + ", Font Name: " + toSet.getFont().getName() + ", Size: " + toSet.getFont().getSize());
cell.setStyle(availableStyles[i]);

appliedStyle = true;
break;
}
}


An the debug print out comes out as:
Name: Central Idea, Font Name: Arial, Size: 10
Name: Central Idea, Font Name: Arial, Size: 10

I have followed the examples and cant see where i am going wrong. Any help would be much appreciated.

Hi,

Thanks for your code,

We found the issue and will figure it out soon.

Thanks for being patient!

Hi,

Please try this attached fix, thank you.

Hi,

Thanks for that, it seems to be working great, formatting applied so far all displays correctly!

Thanks again