Hello, I have an issue, when I try to set an HtmlString on the cell, if I set the font size to a double value, it is converted to an integer value. An example:
style.getFont().setDoubleSize(Double.parseDouble("12.5"));
workbook.getWorksheets().get(0).getCells().get(STRING_INDEX).setStyle(style);
workbook.getWorksheets().get(0).getCells().get(STRING_INDEX).setHtmlString("mimmo");
When I open the Workbook the font size of the STRING_INDEX cell is 12 and not 12.5.
is it a Bug?
@PietroTGK
Which version are you using?
We tried the latest version 25.4 . It works fine.
Workbook workbook = new Workbook();
Cells cells = workbook.getWorksheets().get(0).getCells();
Cell cell = cells.get("A1");
cell.putValue("sdsdf");
Style style = cell.getStyle();
style.getFont().setDoubleSize(12.25);
cell.setStyle(style);
System.out.print(cell.getHtmlString());
workbook.save(dir +"dest.xlsx");
24.6
Thanks for the reply. I’ll try the latest version.
I looked more carefully at the snippet you sent. You don’t set the value on cell with the method setHtmlString()
but with putValue()
.
I have the same issue also with the 25.4 version.
@PietroTGK,
I evaluated your issue further. It seems the setHtmlString overrides the style being set. Please interchange the lines of code. First you will set HTML string then specify/set style. I will work:
e.g.,
Workbook workbook = new Workbook();
Cells cells = workbook.getWorksheets().get(0).getCells();
Cell cell = cells.get("A1");
//Set HTML string
cell.setHtmlString("mimmo");
Style style = cell.getStyle();
style.getFont().setDoubleSize(Double.parseDouble("12.5"));
cell.setStyle(style);
System.out.print(cell.getHtmlString());
workbook.save("d:\\files\\dest1.xlsx");
output:
<Font Style="FONT-FAMILY: Arial;FONT-SIZE: 12.5pt;COLOR: #000000;VERTICAL-ALIGN: middle;">mimmo</Font>
In this way it works.
Thanks.
@PietroTGK,
Good to know that your issue is sorted out by following the suggested process. Please feel free to write us back if you have further queries or comments.