Return-Path: Delivered-To: apmail-jakarta-poi-user-archive@www.apache.org Received: (qmail 77861 invoked from network); 18 Jan 2006 18:25:38 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 18 Jan 2006 18:25:38 -0000 Received: (qmail 71140 invoked by uid 500); 18 Jan 2006 18:25:29 -0000 Delivered-To: apmail-jakarta-poi-user-archive@jakarta.apache.org Received: (qmail 71025 invoked by uid 500); 18 Jan 2006 18:25:28 -0000 Mailing-List: contact poi-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "POI Users List" Reply-To: "POI Users List" Delivered-To: mailing list poi-user@jakarta.apache.org Received: (qmail 70962 invoked by uid 99); 18 Jan 2006 18:25:28 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Jan 2006 10:25:28 -0800 X-ASF-Spam-Status: No, hits=2.6 required=10.0 tests=DNS_FROM_RFC_ABUSE,HTML_10_20,HTML_MESSAGE,SUBJ_ALL_CAPS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [206.190.39.45] (HELO web54212.mail.yahoo.com) (206.190.39.45) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 18 Jan 2006 10:25:27 -0800 Received: (qmail 97517 invoked by uid 60001); 18 Jan 2006 18:25:06 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=tavd2b33EUCZQRryUxcwMCX/VFnzwiyQMeYc5ns8V+KS435Tu79PpaxfXbwni9aWXIZqNtGMHvuOeGtfgcYetEZZpogehUfSZK3+TVSeiEh/WL39j0R2n1R1V1g1+vKBzxXzf6YVr7E7VP5Y/Pq/5r3+qsLJm8oYNPsEtejkLVA= ; Message-ID: <20060118182506.97515.qmail@web54212.mail.yahoo.com> Received: from [200.16.0.130] by web54212.mail.yahoo.com via HTTP; Wed, 18 Jan 2006 12:25:05 CST Date: Wed, 18 Jan 2006 12:25:05 -0600 (CST) From: Nancy Espinoza Subject: RE: HSSF POI READING FORMULAS IN AN EXCEL ARCHIVE To: POI Users List In-Reply-To: <34B80AFC74D7914EAF5F70B69CC8B1D2110C002E@iowacexch1.ic.ncs.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-2092611863-1137608705=:96962" Content-Transfer-Encoding: 8bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N --0-2092611863-1137608705=:96962 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Thanks guys for the answers I resolve my problem Anyway thanks for your help :) Have a nice day regards, NANCY "Donahue, Michael" escribi�: If the real question is how do you determine if you have a data or a number here is how you do that. Check the Cell's format it will tell you if the format is a Date format or a number format. Then you can use that to determine when to convert the double to a Date object. This should work unless you use a non-standard format. Good Luck, - MJD -----Original Message----- From: ichy [mailto:ichylinux@gmail.com] Sent: Wednesday, January 18, 2006 11:06 AM To: POI Users List Subject: Re: HSSF POI READING FORMULAS IN AN EXCEL ARCHIVE Hi Nancy. well, this is a little code that i tested to get date value. --------------------------------------------------------------------------- import java.io.FileInputStream; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; public class Main { public static void main( String[] args ) { String filename = "date-formula.xls"; HSSFWorkbook hWorkbook; try { hWorkbook = new HSSFWorkbook( new FileInputStream( filename ) ); HSSFSheet hSheet = hWorkbook.getSheetAt( 0 ); HSSFRow hRow = hSheet.getRow( 0 ); HSSFCell hCell = hRow.getCell( (short)0 ); HSSFCell hCell2 = hRow.getCell( (short)1 ); System.out.println("type of A1=" + getCellTypeString( hCell.getCellType() ) ); System.out.println( hCell.getNumericCellValue() ); System.out.println( hCell.getDateCellValue() ); System.out.println("type of B1=" + getCellTypeString( hCell2.getCellType() ) ); System.out.println( hCell2.getNumericCellValue() ); System.out.println( hCell2.getDateCellValue() ); } catch ( Exception e ) { e.printStackTrace(); } } private static String getCellTypeString( int cellType ) { switch ( cellType ) { case HSSFCell.CELL_TYPE_BLANK : return "BLANK"; case HSSFCell.CELL_TYPE_BOOLEAN : return "BOOLEAN"; case HSSFCell.CELL_TYPE_ERROR : return "ERROR"; case HSSFCell.CELL_TYPE_FORMULA : return "FORMULA"; case HSSFCell.CELL_TYPE_NUMERIC : return "NUMERIC"; case HSSFCell.CELL_TYPE_STRING : return "STRING"; default : return "UNKNOWN"; } } } --------------------------------------------------------------------------- if i run the code above with a excel file "date-formula.xls" which has date "2006/1/20" on cell A1 and formula "A1+1" on cell B1, i get a result as: type of A1=NUMERIC 38737.0 Fri Jan 20 00:00:00 JST 2006 type of B1=FORMULA 38738.0 Sat Jan 21 00:00:00 JST 2006 so, if you know that a1 has a number, you can use getNumericCellValue() and if you know that a1 has a date, you can use getDateCellValue(). but you may not be able to know which cell type a1 has by the formula "A1+1". and the number 38737 and 38738 are the way excel handles date values if i remember correctly. i hope this will help you a bit. regards ichy --------------------------------------------------------------------- To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org Mailing List: http://jakarta.apache.org/site/mail2.html#poi The Apache Jakarta Poi Project: http://jakarta.apache.org/poi/ **************************************************************************** This email may contain confidential material. If you were not an intended recipient, Please notify the sender and delete all copies. We may monitor email to and from our network. **************************************************************************** --------------------------------------------------------------------- To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org Mailing List: http://jakarta.apache.org/site/mail2.html#poi The Apache Jakarta Poi Project: http://jakarta.apache.org/poi/ __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam �gratis! Reg�strate ya - http://correo.espanol.yahoo.com/ --0-2092611863-1137608705=:96962--