コード例 #1
0
ファイル: ReportGear.java プロジェクト: sharlamov/iwork
 private void init(Workbook book) {
   if (book instanceof HSSFWorkbook) {
     parsingBook = HSSFEvaluationWorkbook.create((HSSFWorkbook) book);
     renderingBook = HSSFEvaluationWorkbook.create((HSSFWorkbook) book);
   } else if (book instanceof XSSFWorkbook) {
     parsingBook = XSSFEvaluationWorkbook.create((XSSFWorkbook) book);
     renderingBook = XSSFEvaluationWorkbook.create((XSSFWorkbook) book);
   }
 }
コード例 #2
0
 public void testHSSFFailsForOver65536() {
   FormulaParsingWorkbook workbook = HSSFEvaluationWorkbook.create(new HSSFWorkbook());
   try {
     FormulaParser.parse("Sheet1!1:65537", workbook, FormulaType.CELL, 0);
     fail("Expected exception");
   } catch (FormulaParseException expected) {
   }
 }
コード例 #3
0
ファイル: XlsFile.java プロジェクト: kvmorozov/sweets
  @Override
  public void afterPropertiesSet() throws Exception {
    if (fileName == null || fileName.isEmpty()) return;

    try {
      workbook = new HSSFWorkbook(getClass().getClassLoader().getResourceAsStream(root + fileName));
      evalWorkbook = HSSFEvaluationWorkbook.create((HSSFWorkbook) workbook);
    } catch (OfficeXmlFileException ox) {
      try {
        workbook =
            new XSSFWorkbook(getClass().getClassLoader().getResourceAsStream(root + fileName));
        evalWorkbook = XSSFEvaluationWorkbook.create((XSSFWorkbook) workbook);
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    isValidConfig = true;
  }
コード例 #4
0
  public void testFormulas() {

    FormulaRecord[] fRecs = mockListen.getFormulaRecords();

    // Check our formula records
    assertEquals(6, fRecs.length);

    InternalWorkbook stubWB = listener.getStubWorkbook();
    assertNotNull(stubWB);
    HSSFWorkbook stubHSSF = listener.getStubHSSFWorkbook();
    assertNotNull(stubHSSF);

    // Check these stubs have the right stuff on them
    assertEquals("Sheet1", stubWB.getSheetName(0));
    assertEquals("Sheet1", stubHSSF.getSheetName(0));
    assertEquals("S2", stubWB.getSheetName(1));
    assertEquals("S2", stubHSSF.getSheetName(1));
    assertEquals("Sh3", stubWB.getSheetName(2));
    assertEquals("Sh3", stubHSSF.getSheetName(2));

    // Check we can get the formula without breaking
    for (int i = 0; i < fRecs.length; i++) {
      HSSFFormulaParser.toFormulaString(stubHSSF, fRecs[i].getParsedExpression());
    }

    // Peer into just one formula, and check that
    //  all the ptgs give back the right things
    Ptg[] ptgs = fRecs[0].getParsedExpression();
    assertEquals(1, ptgs.length);
    assertTrue(ptgs[0] instanceof Ref3DPtg);

    Ref3DPtg ptg = (Ref3DPtg) ptgs[0];
    HSSFEvaluationWorkbook book = HSSFEvaluationWorkbook.create(stubHSSF);
    assertEquals("Sheet1!A1", ptg.toFormulaString(book));

    // Now check we get the right formula back for
    //  a few sample ones
    FormulaRecord fr;

    // Sheet 1 A2 is on same sheet
    fr = fRecs[0];
    assertEquals(1, fr.getRow());
    assertEquals(0, fr.getColumn());
    assertEquals(
        "Sheet1!A1", HSSFFormulaParser.toFormulaString(stubHSSF, fr.getParsedExpression()));

    // Sheet 1 A5 is to another sheet
    fr = fRecs[3];
    assertEquals(4, fr.getRow());
    assertEquals(0, fr.getColumn());
    assertEquals("'S2'!A1", HSSFFormulaParser.toFormulaString(stubHSSF, fr.getParsedExpression()));

    // Sheet 1 A7 is to another sheet, range
    fr = fRecs[5];
    assertEquals(6, fr.getRow());
    assertEquals(0, fr.getColumn());
    assertEquals(
        "SUM(Sh3!A1:A4)", HSSFFormulaParser.toFormulaString(stubHSSF, fr.getParsedExpression()));

    // Now, load via Usermodel and re-check
    HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("3dFormulas.xls");
    assertEquals("Sheet1!A1", wb.getSheetAt(0).getRow(1).getCell(0).getCellFormula());
    assertEquals("SUM(Sh3!A1:A4)", wb.getSheetAt(0).getRow(6).getCell(0).getCellFormula());
  }
コード例 #5
0
 public void testHSSFPassCase() {
   FormulaParsingWorkbook workbook = HSSFEvaluationWorkbook.create(new HSSFWorkbook());
   FormulaParser.parse("Sheet1!1:65536", workbook, FormulaType.CELL, 0);
 }