Bug 58006 - [PATCH] HSSF/XSSFSheet ColumnWidth VBA Compatible Methods
Summary: [PATCH] HSSF/XSSFSheet ColumnWidth VBA Compatible Methods
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.12-FINAL
Hardware: PC All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: POI Developers List
Keywords: PatchAvailable
Depends on:
Reported: 2015-06-06 16:37 UTC by Hidekatsu Izuno
Modified: 2016-03-13 20:16 UTC (History)
0 users

HSSF/XSSFSheet ColumnWidth VBA Compatible Methods Patch (6.54 KB, application/gzip)
2015-06-06 16:37 UTC, Hidekatsu Izuno

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