Bug 58006

Summary: [PATCH] HSSF/XSSFSheet ColumnWidth VBA Compatible Methods
Product: POI Reporter: Hidekatsu Izuno <hidekatsu.izuno>
Component: HSSFAssignee: POI Developers List <dev>
Status: NEEDINFO ---    
Severity: enhancement Keywords: PatchAvailable
Priority: P2    
Version: 3.12-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: HSSF/XSSFSheet ColumnWidth VBA Compatible Methods Patch

Description Hidekatsu Izuno 2015-06-06 16:37:48 UTC
Created attachment 32798 [details]
HSSF/XSSFSheet ColumnWidth VBA Compatible Methods Patch

POI's set/getColumnWidth is not compatible EXCEL VBA. It is returned EXCEL internal column width value.

I added or modified in HSSF/XSSFSheet below methods for getting 
the VBA compatible column width value.

- set/getStandardWidthInChars (VBA's StandardWidth)
- set/getColumnWidthInChars  (VBA's ColumnWidth)
- getColumnWidthInPoints (VBA's Width)
- getColumnWidthInPixels

These methods require the Standard Font's '0' character's width (px).
So I added ColumnWidthUtil.getStandardCharWidthInPixels(font).
This method is supported below major fonts.

- Calibri
- Arial
- Arial Unicode MS
- Century
- Georgia
- Verdana
- MS Reference Sans Serif
- Times New Roman
- Symbol
- MS Gothic
- MS Mincho
- MS PGothic
- MS PMincho
- MS UI Gothic
- MingLiU
- MingLiU_HKSCS
- MingLiU_HKSCS-ExtB
- MingLiU-ExtB
- Mongolian Baiti
- NSimSun
- Palatino Linotype
- SimHei
- SimSun
- SimSun-ExtB
- Sylfaen
- Meiryo
- Meiryo UI

I tested various conditions. But I'm not completely solve.
below methods still exist small remainders. Although it is enough 
in most cases.

- XSSFSheet#getStandardWidthInChars (error rate is less than 1/1000)
- XSSFSheet#getColumnWidthInChars (error rate is less than 1/1000)
- setStandardWidthInChars (error rate is less than 1/10)
- setColumnWidthInChars (error rate  is less than 1/10)
Comment 1 Dominik Stadler 2016-03-13 20:16:16 UTC
According to the description below the patch is not in a state to be applied directly.