Reading cells with HLOOKUP formulas

0

I'm having a hard time evaluating a formula with the Apache Poi API in a cell that contains the formula HLOOKUP(B9,$AK$8:$AS$68,2,FALSE) .

The same thing happens to be a file .xls or .xlsx .

The excel sheet has a table template that I fill with certain values that come from another site. The cells in the first and second columns of this table are strings. the next cells are numbers, and the last cell is the formula I mentioned above - HLOOKUP(B9,$AK$8:$AS$68,2,FALSE) - and that's the one I can not read the value.

After filling, I can do get and set of all fields, but when I evaluate the formula in switch I'll always stop Cell.CELL_TYPE_ERROR :

        FormulaEvaluator evaluator = my_xls_workbookp.getCreationHelper().createFormulaEvaluator();
        CellReference cellReference = new CellReference("R9");
        Row row = my_worksheetp.getRow(cellReference.getRow());
        Cell cell = row.getCell(cellReference.getCol());
        int cellType = evaluator.evaluateFormulaCell(cell);

        switch (cellType) {
            case Cell.CELL_TYPE_STRING:
                System.out.print(cell.getStringCellValue());
                break;
            case Cell.CELL_TYPE_BOOLEAN:
                System.out.print(cell.getBooleanCellValue());
                break;
            case Cell.CELL_TYPE_NUMERIC:
                System.out.print(cell.getNumericCellValue());
                break;
            case Cell.CELL_TYPE_ERROR:
                break;
                // CELL_TYPE_FORMULA will never happen
            case Cell.CELL_TYPE_FORMULA: 
                break;
        }

A curious question: I do not know if it helps but if after putting the values, open Excel through Office, do nothing in the document, and close again, I get the message from Office saying:

  

The following features can not be stored in books without   permission for macros: The function of excel 4.0 stored in names   defined. To save a file with these features, click   click No, and then select a file type with permission.   for Macros in the File Type list. To continue saving as   a book without macros permission, click Yes.

I choose the "Yes" option and after that I read the file, I can already do getNumericCellValue() and get the value, but that does not interest me because I have to get the value when I am writing.

Does this API fail to read $AK$8:$AS$68 directly, do I have to do something?

    
asked by anonymous 17.10.2015 / 22:49

0 answers