Examples of FormulaRecordAggregate


Examples of org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate

            // re-parsing the formula text also works, but is a waste of time
            // It is useful from time to time to run all unit tests with this code
            // to make sure that all formulas POI can evaluate can also be parsed.
            return HSSFFormulaParser.parse(cell.getCellFormula(), _uBook, FormulaType.CELL, _uBook.getSheetIndex(cell.getSheet()));
        }
        FormulaRecordAggregate fra = (FormulaRecordAggregate) cell.getCellValueRecord();
        return fra.getFormulaTokens();
    }
View Full Code Here

Examples of org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate

    HSSFRow rowSUM2D = sheet.getRow(5);

    // Test the sum
    HSSFCell cellSUM = rowSUM.getCell(0);

    FormulaRecordAggregate frec = (FormulaRecordAggregate) cellSUM.getCellValueRecord();
    Ptg[] ops = frec.getFormulaRecord().getParsedExpression();
    assertEquals(2, ops.length);
    assertEquals(AreaPtg.class, ops[0].getClass());
    assertEquals(FuncVarPtg.class, ops[1].getClass());

    // Actually stored as C1 to C65536
View Full Code Here

Examples of org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate

    while(it.hasNext()) {
      HSSFCell cell = (HSSFCell)it.next();
      if(cell.getCellType() != HSSFCell.CELL_TYPE_FORMULA) {
          continue;
      }
      FormulaRecordAggregate record = (FormulaRecordAggregate) cell.getCellValueRecord();
      FormulaRecord r = record.getFormulaRecord();
      Ptg[] ptgs = r.getParsedExpression();
     
      String cellRef = new CellReference(row.getRowNum(), cell.getColumnIndex(), false, false).formatAsString();
      if(false && cellRef.equals("BP24")) { // TODO - replace System.out.println()s with asserts
        System.out.print(cellRef);
View Full Code Here

Examples of org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate

        CellValueRecordInterface[] cvrs = ns.getSheet().getValueRecords();
        for (int i = 0; i < cvrs.length; i++) {
            CellValueRecordInterface cvr = cvrs[i];
            if(cvr instanceof FormulaRecordAggregate) {
                FormulaRecordAggregate fr = (FormulaRecordAggregate)cvr;

                if(i == 0) {
                    assertEquals(70164.0, fr.getFormulaRecord().getValue(), 0.0001);
                    assertNull(fr.getStringRecord());
                } else if (i == 1) {
                    assertEquals(0.0, fr.getFormulaRecord().getValue(), 0.0001);
                    assertNotNull(fr.getStringRecord());
                    assertEquals("70164", fr.getStringRecord().getString());
                } else {
                    assertEquals(0.0, fr.getFormulaRecord().getValue(), 0.0001);
                    assertNotNull(fr.getStringRecord());
                    assertEquals("90210", fr.getStringRecord().getString());
                }
            }
        }
        assertEquals(3, cvrs.length);
    }
View Full Code Here

Examples of org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate

   * operands to the range (:) operator.
   *
   */
  private static void pokeInOffsetFormula(HSSFCell cell) {
    cell.setCellFormula("1");
    FormulaRecordAggregate fr;
    try {
      Field field = HSSFCell.class.getDeclaredField("_record");
      field.setAccessible(true);
      fr = (FormulaRecordAggregate) field.get(cell);
    } catch (IllegalArgumentException e) {
      throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
      throw new RuntimeException(e);
    } catch (NoSuchFieldException e) {
      throw new RuntimeException(e);
    }
    Ptg[] ptgs = {
        new RefPtg("C1"),
        new RefPtg("C1"),
        new IntPtg(0),
        new RefPtg("B1"),
        new FuncVarPtg("OFFSET", (byte)3),
        RangePtg.instance,
        AttrPtg.SUM,
      };
    fr.setParsedExpression(ptgs);
  }
View Full Code Here

Examples of org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate

        CellValueRecordInterface[] cvrs = ns.getSheet().getValueRecords();
        for (int i = 0; i < cvrs.length; i++) {
            CellValueRecordInterface cvr = cvrs[i];
            if(cvr instanceof FormulaRecordAggregate) {
                FormulaRecordAggregate fr = (FormulaRecordAggregate)cvr;

                if(i == 0) {
                    assertEquals(70164.0, fr.getFormulaRecord().getValue(), 0.0001);
                    assertNull(fr.getStringRecord());
                } else if (i == 1) {
                    assertEquals(0.0, fr.getFormulaRecord().getValue(), 0.0001);
                    assertNotNull(fr.getStringRecord());
                    assertEquals("70164", fr.getStringRecord().getString());
                } else {
                    assertEquals(0.0, fr.getFormulaRecord().getValue(), 0.0001);
                    assertNotNull(fr.getStringRecord());
                    assertEquals("90210", fr.getStringRecord().getString());
                }
            }
        }
        assertEquals(3, cvrs.length);
    }
View Full Code Here

Examples of org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate

        }
        switch (cellType)
        {

            case CELL_TYPE_FORMULA :
                FormulaRecordAggregate frec;

                if (cellType != _cellType) {
                    frec = _sheet.getSheet().getRowsAggregate().createFormula(row, col);
                } else {
                    frec = (FormulaRecordAggregate) _record;
                    frec.setRow(row);
                    frec.setColumn(col);
                }
                if (setValue)
                {
                    frec.getFormulaRecord().setValue(getNumericCellValue());
                }
                frec.setXFIndex(styleIndex);
                _record = frec;
                break;

            case CELL_TYPE_NUMERIC :
                NumberRecord nrec = null;
View Full Code Here

Examples of org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate

        }

        if (_cellType == CELL_TYPE_FORMULA) {
            // Set the 'pre-evaluated result' for the formula
            // note - formulas do not preserve text formatting.
            FormulaRecordAggregate fr = (FormulaRecordAggregate) _record;
            fr.setCachedStringResult(hvalue.getString());
            // Update our local cache to the un-formatted version
            _stringValue = new HSSFRichTextString(value.getString());

            // All done
            return;
View Full Code Here

Examples of org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate

            return;
        }
        int sheetIndex = _book.getSheetIndex(_sheet);
        Ptg[] ptgs = HSSFFormulaParser.parse(formula, _book, FormulaType.CELL, sheetIndex);
        setCellType(CELL_TYPE_FORMULA, false, row, col, styleIndex);
        FormulaRecordAggregate agg = (FormulaRecordAggregate) _record;
        FormulaRecord frec = agg.getFormulaRecord();
        frec.setOptions((short) 2);
        frec.setValue(0);

        //only set to default if there is no extended format index already set
        if (agg.getXFIndex() == (short)0) {
            agg.setXFIndex((short) 0x0f);
        }
        agg.setParsedExpression(ptgs);
    }
View Full Code Here

Examples of org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate

            default:
                throw typeMismatch(CELL_TYPE_STRING, _cellType, false);
            case CELL_TYPE_FORMULA:
                break;
        }
        FormulaRecordAggregate fra = ((FormulaRecordAggregate)_record);
        checkFormulaCachedValueType(CELL_TYPE_STRING, fra.getFormulaRecord());
        String strVal = fra.getStringValue();
        return new HSSFRichTextString(strVal == null ? "" : strVal);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.