Hi,
        Thanks for your feedback, but your case can not solve my problem.

Thanks.
Jianfeng Jiang
-----Original Message-----
From: xio [mailto:[EMAIL PROTECTED] 
Sent: 2008年10月14日 11:54
To: [email protected]
Subject: Excel Column Width Unit Converter[pixels - excel column width units]




Hi   For one yearbook editing system, which buid the excel file for printing, i 
have used the poi to generate excel file. The sheet built should fit the size 
for paper accurately( +- 2pixels ), like A4 paper or others...    it s a rough 
road in finding the converter for Pixels-Excel Column Width Units changing.    
at first(2008.04), i found a solution from the mail list  Excel column widths - 
an almost complete solution/explanation , and it made me so happy that it make 
me ride out the storm.    soon(2008.05), i found it can't meet the requirements 
in my system. so i set the column width by hand in the excel sheet, and 
observer it, find the law.and then write a new algorithm to do it ...   i m so 
lucky, that, at the end of  the system developing, yesterday, i found the 
algorithm more accurately and more simply. the column width is muti-256, which 
7pixels equals 256 excel column width units, but in the 7 pixels, it has a 
map(not average increasing):36,73,109,146,182,219,256.  
  i don't know if it can do well in the other environment, my computer is xp, 
and 96dpi. maybe it s useful to someone who do the same job as mine.   the 
code: package name.xio.util.poi; /** * the units converter for excel  * @author 
[EMAIL PROTECTED] * */public class MSExcelUtil {  public static final short 
EXCEL_COLUMN_WIDTH_FACTOR = 256; public static final int UNIT_OFFSET_LENGTH = 
7; public static final int[] UNIT_OFFSET_MAP = new int[] { 0, 36, 73, 109, 146, 
182, 219 };  /**  * pixel units to excel width units(units of 1/256th of a 
character width)  * @param pxs  * @return  */ public static short 
pixel2WidthUnits(int pxs) {   short widthUnits = (short) 
(EXCEL_COLUMN_WIDTH_FACTOR * (pxs / UNIT_OFFSET_LENGTH));   widthUnits += 
UNIT_OFFSET_MAP[(pxs % UNIT_OFFSET_LENGTH)];   return widthUnits; }  /**  * 
excel width units(units of 1/256th of a character width) to pixel units   * 
@param widthUnits  * @return  */ public static int widthUnits2Pixel(short 
widthUnits) {   in
 t pixels = (widthUnits / EXCEL_COLUMN_WIDTH_FACTOR) * UNIT_OFFSET_LENGTH;    
int offsetWidthUnits = widthUnits % EXCEL_COLUMN_WIDTH_FACTOR;   pixels += 
Math.round((float) offsetWidthUnits / ((float) EXCEL_COLUMN_WIDTH_FACTOR / 
UNIT_OFFSET_LENGTH));    return pixels; } } 
_________________________________________________________________
Invite your mail contacts to join your friends list with Windows Live Spaces. 
It's easy!
http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to