Hello,
reading two ranges from the same excel with the same range width (different number of columns but with same total columns widths) and saving them as HTML I obtain two HTML table having different widths.
html-table-width.png (6.4 KB)
Attached a code example:
html-table-width.zip (13.9 KB)
Thanks in advance,
Federico
@federico.mameli,
Thanks for the resource files and screenshot.
We will evaluate your issue and get back to you soon.
@federico.mameli
By checking the sample file, we found that the width of columns B and E is the same. But the sum of the widths of columns F and G is greater than the width of column C. So there is a difference in width between the two ranges.
Checking on excel, it seems that column C width is the sum of column F and G widths
d0d96a3c-8948-48c4-b08d-d2b250b9e0e0.jpg (14.5 KB)
d0d96a3c-8948-48c4-b08d-d2b250b9e0e0.jpg (14.5 KB)
a2f84540-9f6e-476b-81c7-e3340e32797c.jpg (21.3 KB)
Reading column widths by rangeByName.getWorksheet().getCells().getColumnWidth(col) actually we noticed that they don’t correspond to those we saw from excel, each one differs for a 0.13
6c0f3aec-ff0a-4e7f-9f78-f6ca4fef56ad.jpg (8.2 KB)
@federico.mameli,
To make you understand, I have done the width comparison of column C and columns (F and G) in pixels. You can notice column C 's width is 285 pixels. The sum of widths for columns F and G is 290 pixels. See the screenshots for your reference.
sc_onecol.png (38.0 KB)
sc_twocols.png (34.4 KB)
In short, it is expected behaviour in the output HTMLs.
Is there any way to save it in html where if excel says in its own unit of measure (I don’t know what it is) that column c is 40 and f and g are 20 their sum is equal to 40?
I know I have not explained myself very well…
The problem is that users usually look at column widths like 20 and 40 and not pixels. and its’ excel responsibility if it doesn’t match.
If there is a workaround or a trick to make it work like this… It wolud be fine for me!!
Thanks
@federico.mameli,
I am afraid, there is pixelamtic difference for widths of C column vs (F + G) columns, so you have to set the widths of F and G columns manually to try to match their sum with C column to get same widths in HTMLs using your own code by yourselves. See the following sample code for your reference.
e.g.,
Sample code:
Workbook workbook = new Workbook("d:\\files\\tables.xlsx");
Worksheet worksheet = workbook.getWorksheets().get(0);
//Get C column width in pixels
System.out.println("C column width in pixels: " + worksheet.getCells().getColumnWidthPixel(2));
//Get F column width in pixels
System.out.println("F column width in pixels: " + worksheet.getCells().getColumnWidthPixel(5));
//Get G column width in pixels
System.out.println("G column width in pixels: " + worksheet.getCells().getColumnWidthPixel(6));
//Set F and G column widths in pixels accordingly
worksheet.getCells().setColumnWidthPixel(5, worksheet.getCells().getColumnWidthPixel(2)/2);
worksheet.getCells().setColumnWidthPixel(6, worksheet.getCells().getColumnWidthPixel(2)/2);
//Get final F column widths in pixels
System.out.println("Final F column width in pixels: " + worksheet.getCells().getColumnWidthPixel(5));
System.out.println("Final G column width in pixels: " + worksheet.getCells().getColumnWidthPixel(6));