Bug 68094

Summary: In 5.2.4 After called autoSizeColumn function, the returned column width is smaller than in 5.2.3, which makes the columns to be cut off
Product: POI Reporter: Coco Dai <coco.dai>
Component: SS CommonAssignee: POI Developers List <dev>
Status: NEW ---    
Severity: regression CC: keilhofer
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: other   
Bug Depends on:    
Bug Blocks: 68245    
Attachments: Tab generaged by 5.2.3 (expected) and tab generated by 5.2.4
File auto changed the column size with 5.2.5
result of 5.2.3, 5.2.4, 5.2.5

Description Coco Dai 2023-11-07 09:13:57 UTC
Created attachment 39351 [details]
Tab generaged by 5.2.3 (expected) and tab generated by 5.2.4

My OS is Win11

org.apache.poi.ss.usermodel.Sheet.autoSizeColumn

5.2.3
------------Before resize column 0, the column width is 2048
------------After resize column 0, the column width is 4462

5.2.4
------------Before resize column 0, the column width is 2048
------------After resize column 0, the column width is 3718
Comment 1 PJ Fanning 2023-11-08 14:00:01 UTC
I think this is related to https://github.com/apache/poi/pull/541.
Comment 2 Coco Dai 2023-11-09 05:59:11 UTC
Thanks for your quick response! I'm wondering in which release would the fix be available?

We upgraded the library due to security policy, and now the function is broken. 

Thanks,
Coco Dai
Comment 3 PJ Fanning 2023-11-09 09:03:41 UTC
v5.2.5 should be released in a few weeks. It would be helpful if you tried testing using a snapshot version of POI. They can be found here - https://ci-builds.apache.org/job/POI/job/POI-DSL-1.8/lastSuccessfulBuild/artifact/build/dist/maven/

The change related to https://github.com/apache/poi/pull/541 does not revert to the v5.2.3 behaviour. It tries to improve the width calculations by not rounding one of the intermediate values.
Comment 4 Coco Dai 2023-11-20 08:59:08 UTC
Created attachment 39388 [details]
File auto changed the column size with 5.2.5
Comment 5 Coco Dai 2023-11-20 09:00:35 UTC
The file generated with 5.2.5 still have column content be cut off a little bit.see attachment
Comment 6 Coco Dai 2023-11-20 09:58:23 UTC
Created attachment 39389 [details]
result of 5.2.3, 5.2.4, 5.2.5
Comment 7 Coco Dai 2023-11-29 02:57:29 UTC
The content would still be cut off 1 char at J50, this looks not totally fixed for me.
Comment 8 whaid 2023-11-29 11:10:49 UTC
(In reply to Coco Dai from comment #7)
> The content would still be cut off 1 char at J50, this looks not totally
> fixed for me.

Yes, same for me, it's not totally fixed. Content is still cut off!
Worked good in version 5.2.3.
Comment 9 Dominik Stadler 2024-02-25 19:42:17 UTC
Unfortunately autosizing often cannot be 100% accurate because of different font-installations, special characters, operating-systems, Excel vs. LibreOffice and other factors, so we likely cannot make it work always perfectly!

Even when opening the same Excel file in Excel and LibreOffice, there is very often a difference in how wide columns are.

We might consider a customizable "adjustment factor" which would allow users to adjust it to their given environment.
Comment 10 Dominik Stadler 2024-02-26 07:11:38 UTC
*** Bug 68245 has been marked as a duplicate of this bug. ***
Comment 11 Dominik Stadler 2024-02-26 07:13:41 UTC
See https://bz.apache.org/bugzilla/attachment.cgi?id=39602 in bug #68245 for a standalone project to compare results of the two versions.

Things to note from this test-case:
* LibreOffice shows the columns properly, only Excel shows columns as "too small", so not even the UIs agree on how to handle this :(