HSSFCell.getCellFormula() returns #NAME for formulas like =WENN(A1>B1;"a1>b1";"A1<B1"). The same result for =WENN(ISTLEER(A1);"a1>b1";"A1<B1"). A Formula like =WENN(A1;"a1>b1";"A1<B1") does work.
how is this formula entered? reading from an excel file or using the api? don't recognize WENN but I guess that's just i18ed for IF?
Yes, it is the IF-Formula. The formula is read from an Excel-File.
can you attach the file and/or short snippet of the code you're using? thanks
Hello Danny, thanks for the fast reply Frank Wolter here is my (stripped) code: public boolean parseSheet(String sheetname ) { m_SheetNameExcel = sheetname; m_SheetNameDisplay = m_SheetNameExcel; m_visibleRange = null; m_cellsWithSheetReferences.clear(); HSSFCellStyle c_style; int col_n = 0; int row_n = 0; HSSFRow phyRow = null; HSSFSheet sheet = m_workbook.getSheet(sheetname); HSSFFont cellfont = m_workbook.getFontAt((short)0); logger.debug( "ENTER parseSheet(sheetname=" + sheetname + ")" ); int rowNum = sheet.getLastRowNum(); Iterator rows = sheet.rowIterator(); HSSFRow row; while( rows.hasNext()) { row = (HSSFRow) rows.next(); row_n = row.getRowNum(); // Iterate over each cell in the row and print out the cell's content Iterator cells = row.cellIterator(); short fontindex; short c_bcolor; short c_fcolor; HSSFCell cell; while( cells.hasNext()) { cell = (HSSFCell) cells.next(); col_n = cell.getCellNum(); logger.info("Working on cell(row="+ (row_n) + ", col=" + (col_n) + ")"); try { c_style = cell.getCellStyle(); switch ( cell.getCellType() ) { case HSSFCell.CELL_TYPE_NUMERIC: break; case HSSFCell.CELL_TYPE_STRING: break; case HSSFCell.CELL_TYPE_BLANK: break; case HSSFCell.CELL_TYPE_FORMULA: // HERE THE PROBLEM OCCURS: logger.debug("Formula: " + cell.getCellFormula()); break; default: logger.error( "unsuported cell type in sheet'" + sheetname + "', row=" + row_n + ", col=" + col_n); break; } } catch ( Exception e ) { logger.error("Exception for cell("+ row_n + ", " + col_n + ") Exception:" + e.toString()); e.printStackTrace(); } /* end catch() */ } //end while } //end first while
can you attach the file you're reading as well?
Created attachment 5805 [details] offending excel file
We had some formula parser patches and the result of reading/writing your excel files keeps the values intact. Please verify.
Thanks for the correction. Everything works fine with version 2.0 pre1.