Bug 61454 - [PATCH] Example ToHtml does not respect column width and long cell content breaks html layout
Summary: [PATCH] Example ToHtml does not respect column width and long cell content br...
Alias: None
Product: POI
Classification: Unclassified
Component: SS Common (show other bugs)
Version: 3.16-FINAL
Hardware: PC All
: P2 minor (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2017-08-24 20:23 UTC by Christian Fröhler
Modified: 2017-09-19 03:34 UTC (History)
0 users

Screenshot of the broken layout - column with long content. (72.67 KB, image/png)
2017-08-24 20:23 UTC, Christian Fröhler
Proposed patch for Bug 61454 - git patch file (4.90 KB, patch)
2017-08-24 20:27 UTC, Christian Fröhler
Details | Diff
Screenshot after the fix (319.10 KB, image/png)
2017-08-24 20:28 UTC, Christian Fröhler
Excel file used for testing (548.87 KB, application/octet-stream)
2017-08-24 20:47 UTC, Christian Fröhler

Note You need to log in before you can comment on or make changes to this bug.
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