Sumit, I don't understand how it would work for you. You must have known some tricks to make it work. Running the sample code from the apache site gives a nullpointer exception. I have to add one line to make work: FileInputStream fis = new FileInputStream("c:/temp/test.xls"); HSSFWorkbook wb = new HSSFWorkbook(fis); HSSFSheet sheet = wb.getSheetAt(0); HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(sheet, wb); // suppose your formula is in B3 CellReference cellReference = new CellReference("B3"); HSSFRow row = sheet.getRow(cellReference.getRow()); HSSFCell cell = row.getCell(cellReference.getCol()); evaluator.setCurrentRow(row); /*I add this*/ HSSFFormulaEvaluator.CellValue cellValue = evaluator.evaluate(cell);
The test.xls only has a very simple IF: IF(1>0, 1, 0). When I test it, the cellValue.getCellType() = 5, which is CELL_TYPE_ERROR. When I run the debugger, I saw the code generate a function called specialflag and then an error. I tested this with the 2.5.1 download as well as the current code base from apache svn. The results are all the same. Colin [EMAIL PROTECTED] wrote: The IF function in HSSF API is a bit tricky... but it does work to some extent. I agree that it doesn't work in most of the usual scenarios. Like it doesn't evaluate AND / OR conditions in the logical_test, it gives problem evaluating nested IF conditions etc. Yet I have tried to use it to the fullest possible extent.... post your problem and lets see if we can solve it. Regards, Sumit Colin Zhao 03/25/2006 11:39 AM Please respond to "POI Users List" To poi-user@jakarta.apache.org cc Subject Function evaluation with IF Has anyone tried the IF function evaluation? It doesn't seem to work yet. I was going through the source code and have no clue how it is implemented or to be implemented. --------------------------------- Blab-away for as little as 1¢/min. Make PC-to-Phone Calls using Yahoo! Messenger with Voice. +=========================================================+ This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation. +=========================================================+ --------------------------------- Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ countries) for 2¢/min or less.