Return-Path: Delivered-To: apmail-jakarta-poi-user-archive@www.apache.org Received: (qmail 70327 invoked from network); 9 Aug 2006 14:09:12 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 9 Aug 2006 14:09:12 -0000 Received: (qmail 77514 invoked by uid 500); 9 Aug 2006 14:09:09 -0000 Delivered-To: apmail-jakarta-poi-user-archive@jakarta.apache.org Received: (qmail 77495 invoked by uid 500); 9 Aug 2006 14:09:09 -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 77484 invoked by uid 99); 9 Aug 2006 14:09:09 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 09 Aug 2006 07:09:09 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: neutral (asf.osuosl.org: local policy) Received: from [192.249.46.190] (HELO mail1.utc.com) (192.249.46.190) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 09 Aug 2006 07:09:08 -0700 Received: (from uucp@localhost) by mail1.utc.com (8.10.0/8.10.0) id k79E8gZ14402; Wed, 9 Aug 2006 10:08:42 -0400 (EDT) Received: from uusnwa1u.utc.com(159.82.82.46) by mail1.utc.com via csmap (V6.0) id srcAAAT8aWhC; Wed, 9 Aug 06 10:08:42 -0400 Received: from pusehg0h.eh.pweh.com (pusehg0h.eh.pweh.com [10.30.201.32]) by uusnwa1u.utc.com (Switch-3.1.9/Switch-3.1.0) with ESMTP id k79E8eCh021374; Wed, 9 Aug 2006 10:08:42 -0400 (EDT) Received: by pusehg0h.eh.pweh.com with Internet Mail Service (5.5.2657.72) id <34N5JY6C>; Wed, 9 Aug 2006 10:08:39 -0400 Message-ID: <1594C3C2674B7F4F9BFC8BD8F8854D260112CBAD@pusehe0q.eh.pweh.com> From: "Blanchette, Nicole" To: "'Avik Sengupta'" Cc: poi-user@jakarta.apache.org Subject: RE: stuck on formula evaluations Date: Wed, 9 Aug 2006 10:05:44 -0400 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2657.72) Content-Type: text/plain; charset="iso-8859-1" X-Scanned-By: MIMEDefang 2.51 on 159.82.82.46 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Still getting the same error, but thanks, I didn't even think about that. I just changed it to convert them to doubles before setting the cell values. It still isn't evaluating the formula. -----Original Message----- From: Avik Sengupta [mailto:avik.sengupta@itellix.com] Sent: Wednesday, August 09, 2006 9:51 AM To: Blanchette, Nicole Cc: poi-user@jakarta.apache.org Subject: Re: stuck on formula evaluations Also, you seem to be settings string as values to the cell. You need to set them as numbers if you want to use a numeric function on them. On Wednesday 09 August 2006 19:14, Blanchette, Nicole wrote: > The Jakarta page with info on modifying spreadsheets (the HOWTO for HSSF) > said that you had to remove the cells and then put them back in... which > you're right, it does seem weird, and it may not be right for this case. > But I just tried fixing that, and it didn't change my results at all. I'm > still getting the same error message, and the same result is popping up. > > > -----Original Message----- > From: Avik Sengupta [mailto:avik.sengupta@itellix.com] > Sent: Wednesday, August 09, 2006 9:41 AM > To: poi-user@jakarta.apache.org > Cc: Blanchette, Nicole > Subject: Re: stuck on formula evaluations > > > What's that delete cell/ create cell thing ... dont understand why you need > to > do it, but I dont think the formula is going to work if you delete the > cells > that it refers to... > > On Wednesday 09 August 2006 18:57, Blanchette, Nicole wrote: > > Hi, > > I'm trying to read in an existing worksheet with formulas, modify it, and > > then read the results after the formulas have been calculated (for a > > GUI). I have the scratchpad jar and a recent version of the poi. I can't > > seem to evaluate the formula though, and then read back the result. I've > > been testing with a very simple worksheet and program. I've read the > > Formula Evaluation page on the Jakarta website several times, and still > > can't figure it out... Any sort of help would be greatly appreciated. > > > > My error message reads: > > java.lang.NullPointerException > > at > > org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.internalEvaluate(HSSFFor > > >m ulaEvaluator.java:281) > > at > > org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.evaluate(HSSFFormulaEval > > >u ator.java:181) > > at testexcel.Frame1.jbInit(Frame1.java:175) > > at testexcel.Frame1.(Frame1.java:81) > > at testexcel.testexcel.(testexcel.java:20) > > at testexcel.testexcel.main(testexcel.java:50) > > > > relevant part of my code: > > > > 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; > > import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; > > > > > > POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("file > > path")); > > > FileOutputStream stream = new FileOutputStream("new file path"); > > HSSFWorkbook wb = new HSSFWorkbook(fs); > > HSSFSheet sheet = wb.getSheetAt(0); > > HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(sheet, > > wb); > > wb.write(stream); > > > > //get necessary rows & cells > > HSSFRow row1 = sheet.getRow(1); > > HSSFRow row2 = sheet.getRow(2); > > HSSFCell cell1 = row1.getCell((short) 0); > > HSSFCell cell2 = row2.getCell((short) 0); > > > > //remove cells that you're writing to > > row1.removeCell(cell1); > > row2.removeCell(cell2); > > > > //create new cells to insert > > HSSFCell cell5 = row1.createCell((short)0); > > HSSFCell cell6 = row2.createCell((short)0); > > HSSFCell cell7 = row1.getCell((short)1); > > HSSFCell cell8 = row2.getCell((short)1); > > > > //set values of cells > > cell5.setCellValue("5"); //these values actually come from user > > input, from textfield > > cell6.setCellValue("1"); > > cell7.setCellValue("bob"); > > > > //write to workbook > > wb.write(stream); > > stream.close(); > > > > //evaluate simple formula in cell8 (=cell5 - cell6) > > HSSFFormulaEvaluator.CellValue cellValue = > > evaluator.evaluate(cell8); > > String a = String.valueOf(cellValue); //value must be string to > > read out in textfield > > > > //retrieve values > > jLabel6.setText(cell7.getStringCellValue()); > > jTextField3.setText(a); //these text fields are showing up blank > > when I run it > > > > > > I'm new to the list, new to poi, and new to Java, so my apologies if this > > has already been gone over a bunch of times or if I ask a lot of stupid > > questions. > > Thanks, > > Nicole > > > > > > --------------------------------------------------------------------- > > 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/ --------------------------------------------------------------------- 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/