poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Josh Micich <josh.mic...@gmail.com>
Subject Re: Name cell does not work in formula
Date Thu, 29 Jan 2009 19:11:24 GMT
Hello Sapan,

The functionality you seem to be describing has been working since version
3.2.  Here is some code tested to work on both 3.2 and latest svn trunk:
//---------------
HSSFWorkbook wb = new HSSFWorkbook();
HSSFName name = wb.createName();
name.setNameName("SomeName");
name.setReference("Sheet1!B1");
HSSFRow row = wb.createSheet("Sheet1").createRow(0);
row.createCell(1).setCellValue(2.0);
row.createCell(0).setCellFormula("SomeName*5");

HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
CellValue cv = fe.evaluate(row.getCell(0));
assertEquals(10.0, cv.getNumberValue(), 0.0);
//---------------

The evaluator can also evaluate workbooks with defined names that were set
up in Excel:
//---------------
InputStream is = new FileInputStream("nameTest.xls");
HSSFWorkbook wb = new HSSFWorkbook(is);
HSSFRow row = wb.getSheetAt(0).getRow(0);

HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
CellValue cv = fe.evaluate(row.getCell(0));
assertEquals(10.0, cv.getNumberValue(), 0.0);
//---------------

I have just made a guess at the example code you are referring to.  If this
doesn't properly represent what you are trying to do, please post back some
specific code to clarify. It would also be useful to know which version of
POI you are using.  The error message you describe doesn't seem to be
possible from any POI version since 2.5 (when HSSFFormulaEvaluator was
added).  Unfortunately I still don't know how exactly your bug occurred.

regards,
Josh

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message