Bug 61454

Summary: [PATCH] Example ToHtml does not respect column width and long cell content breaks html layout
Product: POI Reporter: Christian Fröhler <cfr2017>
Component: SS CommonAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: minor    
Priority: P2    
Version: 3.16-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: Screenshot of the broken layout - column with long content.
Proposed patch for Bug 61454 - git patch file
Screenshot after the fix
Excel file used for testing

Description Christian Fröhler 2017-08-24 20:23:03 UTC
Created attachment 35253 [details]
Screenshot of the broken layout - column with long content.

In class org.apache.poi.ss.examples.html.ToHtml POI provides a very good way of converting Excel sheets to HTML. The resulting html document contains the correct formatting etc. But column width of the original excel file is not respeceted; instead the resulting table is formatted with css directive "table-layout:auto".

In general this is not a problem. Only for there are excel cells with long content (especially if there are no blanks), the resulting table shows a very wide column and the remaining columns can only be seen by using the scroll bar. See attached screenshot.

To fix it, I provide the patch. Patch is based on POI 3.16, but these classes have not changed since a year or so; therefore it shouldn't be a problem to apply to 3.18.
Comment 1 Christian Fröhler 2017-08-24 20:27:40 UTC
Created attachment 35254 [details]
Proposed patch for Bug 61454 - git patch file
Comment 2 Christian Fröhler 2017-08-24 20:28:58 UTC
Created attachment 35255 [details]
Screenshot after the fix
Comment 3 Christian Fröhler 2017-08-24 20:47:09 UTC
Created attachment 35256 [details]
Excel file used for testing
Comment 4 Javen O'Neal 2017-09-19 03:34:38 UTC
Thanks for your contribution.

Unfortunately, due to licensing issues, I don't think we can use the poiWidthToPixels function without the consent of the author.
I've seen several other width to pixel converter codes [1], so it seems there's no one conversion formula that will work on all systems with the variety of display resolutions and densities, OS and JVMs, and installed fonts.

I applied your changes with a simplified poiWidthToPixels function in r1808816.

If we can find a conversion formula that works for everybody (or most everybody), then we should add it somewhere in the main poi package (and simplify this example). Feel free to open a new bug if you want to suggest a conversion formula.

[1] https://mail-archives.apache.org/mod_mbox/poi-user/200810.mbox/%3CBAY124-W1137A2B874ADEEBF932518BA310@phx.gbl%3E