Return-Path: Delivered-To: apmail-poi-user-archive@www.apache.org Received: (qmail 26002 invoked from network); 14 Oct 2008 05:43:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 14 Oct 2008 05:43:51 -0000 Received: (qmail 19314 invoked by uid 500); 14 Oct 2008 05:43:51 -0000 Delivered-To: apmail-poi-user-archive@poi.apache.org Received: (qmail 19306 invoked by uid 500); 14 Oct 2008 05:43:51 -0000 Mailing-List: contact user-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "POI Users List" Delivered-To: mailing list user@poi.apache.org Received: (qmail 19295 invoked by uid 99); 14 Oct 2008 05:43:51 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 Oct 2008 22:43:51 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of darjino@hotmail.com designates 65.54.246.89 as permitted sender) Received: from [65.54.246.89] (HELO bay0-omc1-s17.bay0.hotmail.com) (65.54.246.89) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 14 Oct 2008 05:42:43 +0000 Received: from BAY124-W11 ([207.46.11.174]) by bay0-omc1-s17.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 13 Oct 2008 22:42:59 -0700 Message-ID: X-Originating-IP: [218.5.35.211] From: xio To: Subject: Excel Column Width Unit Converter[pixels - excel column width units] Date: Tue, 14 Oct 2008 13:42:58 +0800 Importance: Normal Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: 8bit MIME-Version: 1.0 X-OriginalArrivalTime: 14 Oct 2008 05:42:59.0377 (UTC) FILETIME=[B748BA10:01C92DBF] X-Virus-Checked: Checked by ClamAV on apache.org for the style problem, i send it again. 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 xio[darjino@hotmail.com] * */ 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) { int 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; } } _________________________________________________________________ Explore the seven wonders of the world http://search.msn.com/results.aspx?q=7+wonders+world&mkt=en-US&form=QBRE --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@poi.apache.org For additional commands, e-mail: user-help@poi.apache.org