Package org.apache.poi.ss.usermodel

Examples of org.apache.poi.ss.usermodel.Cell


    public void test50416LastRowNumber() {
       // Create the workbook with 1 sheet which contains 3 rows
       HSSFWorkbook workbook = new HSSFWorkbook();
       Sheet sheet = workbook.createSheet("Bug50416");
       Row row1 = sheet.createRow(0);
       Cell cellA_1 = row1.createCell(0,Cell.CELL_TYPE_STRING);
       cellA_1.setCellValue("Cell A,1");
       Row row2 = sheet.createRow(1);
       Cell cellA_2 = row2.createCell(0,Cell.CELL_TYPE_STRING);
       cellA_2.setCellValue("Cell A,2");
       Row row3 = sheet.createRow(2);
       Cell cellA_3 = row3.createCell(0,Cell.CELL_TYPE_STRING);
       cellA_3.setCellValue("Cell A,3");
      
       // Test the last Row number it currently correct
       assertEquals(2, sheet.getLastRowNum());
      
       // Shift the first row to the end
View Full Code Here


        {
          final Row headerRow = (Row) rowIterator.next();
          final short cellCount = headerRow.getLastCellNum();
          for (short colIdx = 0; colIdx < cellCount; colIdx++)
          {
            final Cell cell = headerRow.getCell(colIdx);
            if (cell != null)
            {
              while (colIdx > tableModel.getColumnCount())
              {
                tableModel.addColumn(Messages.getString("TableDataSourceEditor.Column",
                    String.valueOf(tableModel.getColumnCount())), Object.class);
              }

              final RichTextString string = cell.getRichStringCellValue();
              if (string != null)
              {
                tableModel.addColumn(string.getString(), Object.class);
              }
              else
              {
                tableModel.addColumn(Messages.getString("TableDataSourceEditor.Column", String.valueOf(colIdx)), Object.class);
              }
            }
          }
        }
      }

      Object[] rowData = null;
      while (rowIterator.hasNext())
      {
        final Row row = (Row) rowIterator.next();
        final short cellCount = row.getLastCellNum();
        if (cellCount == -1)
        {
          continue;
        }
        if (rowData == null || rowData.length != cellCount)
        {
          rowData = new Object[cellCount];
        }

        for (short colIdx = 0; colIdx < cellCount; colIdx++)
        {
          final Cell cell = row.getCell(colIdx);

          final Object value;
          if (cell != null)
          {
            if (cell.getCellType() == Cell.CELL_TYPE_STRING)
            {
              final RichTextString string = cell.getRichStringCellValue();
              if (string != null)
              {
                value = string.getString();
              }
              else
              {
                value = null;
              }
            }
            else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC)
            {
              final CellStyle hssfCellStyle = cell.getCellStyle();
              final short dataFormat = hssfCellStyle.getDataFormat();
              final String dataFormatString = hssfCellStyle.getDataFormatString();
              if (isDateFormat(dataFormat, dataFormatString))
              {
                value = cell.getDateCellValue();
              }
              else
              {
                value = cell.getNumericCellValue();
              }
            }
            else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN)
            {
              value = cell.getBooleanCellValue();
            }
            else
            {
              value = cell.getStringCellValue();
            }
          }
          else
          {
            value = null;
View Full Code Here

         List<String> lstCur = lstLst.get(i);

         for (int j = 0; j < lstCur.size(); j++)
         {
            Cell celCur = rowCur.createCell(j);
            celCur.setCellValue(lstCur.get(j));
         }

         intRowCount++;
      }
View Full Code Here

            for (Object rawR : sheet) {
                xhtml.startElement("tr");
                Row row = (Row) rawR;
                for (Iterator<Cell> ri = row.cellIterator(); ri.hasNext();) {
                    xhtml.startElement("td");
                    Cell cell = ri.next();

                    if (cell.getCellType() == Cell.CELL_TYPE_FORMULA
                            || cell.getCellType() == Cell.CELL_TYPE_STRING) {
                        xhtml.characters(cell.getRichStringCellValue()
                                .getString());
                    } else {
                        XSSFCell xc = (XSSFCell) cell;
                        String rawValue = xc.getRawValue();
                        if (rawValue != null) {
                            xhtml.characters(rawValue);
                        }

                    }

                    // Output the comment in the same cell as the content
                    Comment comment = cell.getCellComment();
                    if (comment != null) {
                        xhtml.characters(comment.getString().getString());
                    }

                    xhtml.endElement("td");
View Full Code Here

        layout = new TextLayout(str.getIterator(), fontRenderContext);
        int defaultCharWidth = (int)layout.getAdvance();

        double width = -1;
        for (Row row : sheet) {
            Cell cell = row.getCell(column);

            if (cell == null) {
                continue;
            }
View Full Code Here

        double width = -1;
        for (int rowIdx = firstRow; rowIdx <= lastRow; ++rowIdx) {
            Row row = sheet.getRow(rowIdx);
            if( row != null ) {

                Cell cell = row.getCell(column);

                if (cell == null) {
                    continue;
                }
View Full Code Here

  public void testMissingWorkbookMissing() throws IOException {
    FormulaEvaluator evaluator = mainWorkbook.getCreationHelper().createFormulaEvaluator();
   
    Sheet lSheet = mainWorkbook.getSheetAt(0);
    Row lARow = lSheet.getRow(0);
    Cell lA1Cell = lARow.getCell(0);
   
    assertEquals(Cell.CELL_TYPE_FORMULA, lA1Cell.getCellType());
    try {
      evaluator.evaluateFormulaCell(lA1Cell);
      fail("Missing external workbook reference exception expected!");
    }catch(RuntimeException re) {
      assertTrue("Unexpected exception: " + re, re.getMessage().indexOf(SOURCE_DUMMY_WORKBOOK_FILENAME) != -1);
View Full Code Here

    }
  }
 
  public void testMissingWorkbookMissingOverride() throws IOException {
    Sheet lSheet = mainWorkbook.getSheetAt(0);
    Cell lA1Cell = lSheet.getRow(0).getCell(0);
    Cell lB1Cell = lSheet.getRow(1).getCell(0);
    Cell lC1Cell = lSheet.getRow(2).getCell(0);
   
    assertEquals(Cell.CELL_TYPE_FORMULA, lA1Cell.getCellType());
    assertEquals(Cell.CELL_TYPE_FORMULA, lB1Cell.getCellType());
    assertEquals(Cell.CELL_TYPE_FORMULA, lC1Cell.getCellType());

    // Check cached values
        assertEquals(10.0d, lA1Cell.getNumericCellValue(), 0.00001d);
        assertEquals("POI rocks!", lB1Cell.getStringCellValue());
        assertEquals(true, lC1Cell.getBooleanCellValue());
   
        // Evaluate
    FormulaEvaluator evaluator = mainWorkbook.getCreationHelper().createFormulaEvaluator();
        evaluator.setIgnoreMissingWorkbooks(true);

    assertEquals(Cell.CELL_TYPE_NUMERIC, evaluator.evaluateFormulaCell(lA1Cell));
    assertEquals(Cell.CELL_TYPE_STRING,  evaluator.evaluateFormulaCell(lB1Cell));
    assertEquals(Cell.CELL_TYPE_BOOLEAN, evaluator.evaluateFormulaCell(lC1Cell));

    assertEquals(10.0d, lA1Cell.getNumericCellValue(), 0.00001d);
    assertEquals("POI rocks!", lB1Cell.getStringCellValue());
    assertEquals(true, lC1Cell.getBooleanCellValue());
  }
View Full Code Here

  }
 

  public void testExistingWorkbook() throws IOException {
    Sheet lSheet = mainWorkbook.getSheetAt(0);
    Cell lA1Cell = lSheet.getRow(0).getCell(0);
    Cell lB1Cell = lSheet.getRow(1).getCell(0);
    Cell lC1Cell = lSheet.getRow(2).getCell(0);
   
    assertEquals(Cell.CELL_TYPE_FORMULA, lA1Cell.getCellType());
    assertEquals(Cell.CELL_TYPE_FORMULA, lB1Cell.getCellType());
    assertEquals(Cell.CELL_TYPE_FORMULA, lC1Cell.getCellType());

    FormulaEvaluator lMainWorkbookEvaluator = mainWorkbook.getCreationHelper().createFormulaEvaluator();
    FormulaEvaluator lSourceEvaluator = sourceWorkbook.getCreationHelper().createFormulaEvaluator();
    Map<String,FormulaEvaluator> workbooks = new HashMap<String, FormulaEvaluator>();
    workbooks.put(MAIN_WORKBOOK_FILENAME, lMainWorkbookEvaluator);
    workbooks.put(SOURCE_DUMMY_WORKBOOK_FILENAME, lSourceEvaluator);
    lMainWorkbookEvaluator.setupReferencedWorkbooks(workbooks);
   
    assertEquals(Cell.CELL_TYPE_NUMERIC, lMainWorkbookEvaluator.evaluateFormulaCell(lA1Cell));
    assertEquals(Cell.CELL_TYPE_STRING, lMainWorkbookEvaluator.evaluateFormulaCell(lB1Cell));
    assertEquals(Cell.CELL_TYPE_BOOLEAN, lMainWorkbookEvaluator.evaluateFormulaCell(lC1Cell));

    assertEquals(20.0d, lA1Cell.getNumericCellValue(), 0.00001d);
    assertEquals("Apache rocks!", lB1Cell.getStringCellValue());
    assertEquals(false, lC1Cell.getBooleanCellValue());
  }
View Full Code Here

          break;
        }
        if(testFocusFunctionName == null || targetFunctionName.equalsIgnoreCase(testFocusFunctionName)) {

          // expected results are on the row below
          Cell expectedValueCell = r.getCell(SS.COLUMN_INDEX_EXPECTED_VALUE);
          if(expectedValueCell == null) {
            int missingRowNum = rowIndex + 1;
            throw new AssertionFailedError("Missing expected values cell for function '"
                + targetFunctionName + ", test" + targetTestName + " (row " +
                missingRowNum + ")");
View Full Code Here

TOP

Related Classes of org.apache.poi.ss.usermodel.Cell

Copyright © 2018 www.massapicom. 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.