Package org.apache.poi.ss.usermodel

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


  private int processFunctionRow(HSSFFormulaEvaluator evaluator, String targetFunctionName,
      String targetTestName, Row formulasRow, Cell expectedValueCell) {

    int result = Result.NO_EVALUATIONS_FOUND; // so far

    Cell c = formulasRow.getCell(SS.COLUMN_INDEX_ACTUAL_VALUE);
    if (c == null || c.getCellType() != Cell.CELL_TYPE_FORMULA) {
      return result;
    }

    CellValue actualValue = evaluator.evaluate(c);

    try {
      confirmExpectedResult("Function '" + targetFunctionName + "': Test: '" + targetTestName + "' Formula: " + c.getCellFormula()
      + " @ " + formulasRow.getRowNum() + ":" + SS.COLUMN_INDEX_ACTUAL_VALUE,
          expectedValueCell, actualValue);
      _evaluationSuccessCount ++;
      if(result != Result.SOME_EVALUATIONS_FAILED) {
        result = Result.ALL_EVALUATIONS_SUCCEEDED;
View Full Code Here


  private static String getTargetFunctionName(Row r) {
    if(r == null) {
      System.err.println("Warning - given null row, can't figure out function name");
      return null;
    }
    Cell cell = r.getCell(SS.COLUMN_INDEX_FUNCTION_NAME);
    if(cell == null) {
      System.err.println("Warning - Row " + r.getRowNum() + " has no cell " + SS.COLUMN_INDEX_FUNCTION_NAME + ", can't figure out function name");
      return null;
    }
    if(cell.getCellType() == Cell.CELL_TYPE_BLANK) {
      return null;
    }
    if(cell.getCellType() == Cell.CELL_TYPE_STRING) {
      return cell.getRichStringCellValue().getString();
    }

    throw new AssertionFailedError("Bad cell type for 'function name' column: ("
        + cell.getCellType() + ") row (" + (r.getRowNum() +1) + ")");
  }
View Full Code Here

  private static String getTargetTestName(Row r) {
    if(r == null) {
      System.err.println("Warning - given null row, can't figure out test name");
      return null;
    }
    Cell cell = r.getCell(SS.COLUMN_INDEX_TEST_NAME);
    if(cell == null) {
      System.err.println("Warning - Row " + r.getRowNum() + " has no cell " + SS.COLUMN_INDEX_TEST_NAME + ", can't figure out test name");
      return null;
    }
    if(cell.getCellType() == Cell.CELL_TYPE_BLANK) {
      return null;
    }
    if(cell.getCellType() == Cell.CELL_TYPE_STRING) {
      return cell.getRichStringCellValue().getString();
    }

    throw new AssertionFailedError("Bad cell type for 'test name' column: ("
        + cell.getCellType() + ") row (" + (r.getRowNum() +1) + ")");
  }
View Full Code Here

                    }
                } else {
                    dateFormat = DateFormat.getTimeInstance(style, locale);
                }
   
                Cell cell = row.createCell(2);
   
                cell.setCellValue(date);
                CellStyle cellStyle = row.getSheet().getWorkbook().createCellStyle();
   
                String javaDateFormatPattern = ((SimpleDateFormat)dateFormat).toPattern();
                String excelFormatPattern = DateFormatConverter.convert(locale, javaDateFormatPattern);
   
                DataFormat poiFormat = row.getSheet().getWorkbook().createDataFormat();
                cellStyle.setDataFormat(poiFormat.getFormat(excelFormatPattern));
                row.createCell(3).setCellValue(dateFormat.format(date));
   
                cell.setCellStyle(cellStyle);
   
                // the formula returns TRUE is the formatted date in column C equals to the string in column D
                row.createCell(4).setCellFormula("TEXT(C"+rowNum+",G"+rowNum+")=D" + rowNum);
                row.createCell(5).setCellValue(javaDateFormatPattern);
                row.createCell(6).setCellValue(excelFormatPattern);
View Full Code Here

     * @param row An instance of either the HSSFRow or XSSFRow classes that
     *            encapsulates information about a row of cells recovered from
     *            an Excel workbook.
     */
    private void rowToCSV(Row row) {
        Cell cell = null;
        int lastCellNum = 0;
        ArrayList<String> csvLine = new ArrayList<String>();

        // Check to ensure that a row was recovered from the sheet as it is
        // possible that one or more rows between other populated rows could be
        // missing - blank. If the row does contain cells then...
        if(row != null) {

            // Get the index for the right most cell on the row and then
            // step along the row from left to right recovering the contents
            // of each cell, converting that into a formatted String and
            // then storing the String into the csvLine ArrayList.
            lastCellNum = row.getLastCellNum();
            for(int i = 0; i <= lastCellNum; i++) {
                cell = row.getCell(i);
                if(cell == null) {
                    csvLine.add("");
                }
                else {
                    if(cell.getCellType() != Cell.CELL_TYPE_FORMULA) {
                        csvLine.add(this.formatter.formatCellValue(cell));
                    }
                    else {
                        csvLine.add(this.formatter.formatCellValue(cell, this.evaluator));
                    }
View Full Code Here

        int firstColumn = range.getFirstColumn();
        int lastColumn = range.getLastColumn();
        final int width = lastColumn - firstColumn + 1;
        SimpleCellWalkContext ctx = new SimpleCellWalkContext();
        Row currentRow = null;
        Cell currentCell = null;

        for (ctx.rowNumber = firstRow; ctx.rowNumber <= lastRow; ++ctx.rowNumber) {
            currentRow = sheet.getRow(ctx.rowNumber);
            if (currentRow == null) {
                continue;
View Full Code Here

   *  we parse.
   */
  public void testXRefs() throws Exception {
      HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("XRefCalc.xls");
      HSSFWorkbook wbData = HSSFTestDataSamples.openSampleWorkbook("XRefCalcData.xls");
      Cell cell;
     
      // VLookup on a name in another file
      cell = wb.getSheetAt(0).getRow(1).getCell(2);
      assertEquals(Cell.CELL_TYPE_FORMULA, cell.getCellType());
      assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCachedFormulaResultType());
      assertEquals(12.30, cell.getNumericCellValue(), 0.0001);
      // WARNING - this is wrong!
      // The file name should be showing, but bug #45970 is fixed
      //  we seem to loose it
      assertEquals("VLOOKUP(PART,COSTS,2,FALSE)", cell.getCellFormula());
     
     
      // Simple reference to a name in another file
      cell = wb.getSheetAt(0).getRow(1).getCell(4);
      assertEquals(Cell.CELL_TYPE_FORMULA, cell.getCellType());
      assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCachedFormulaResultType());
      assertEquals(36.90, cell.getNumericCellValue(), 0.0001);
      // TODO Correct this!
      // The file name should be shown too, see bug #56742
      assertEquals("Cost*Markup_Cost", cell.getCellFormula());
     
     
      // Evaluate the cells
      HSSFFormulaEvaluator eval = new HSSFFormulaEvaluator(wb);
      HSSFFormulaEvaluator.setupEnvironment(
            new String[] { "XRefCalc.xls", "XRefCalcData.xls" },
            new HSSFFormulaEvaluator[] {
                  eval,
                  new HSSFFormulaEvaluator(wbData)
            }
      );
      eval.evaluateFormulaCell(
            wb.getSheetAt(0).getRow(1).getCell(2)
      );     
      eval.evaluateFormulaCell(
            wb.getSheetAt(0).getRow(1).getCell(4)
      );     
     

      // Re-check VLOOKUP one
      cell = wb.getSheetAt(0).getRow(1).getCell(2);
      assertEquals(Cell.CELL_TYPE_FORMULA, cell.getCellType());
      assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCachedFormulaResultType());
      assertEquals(12.30, cell.getNumericCellValue(), 0.0001);
     
      // Re-check ref one
      cell = wb.getSheetAt(0).getRow(1).getCell(4);
      assertEquals(Cell.CELL_TYPE_FORMULA, cell.getCellType());
      assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCachedFormulaResultType());
      assertEquals(36.90, cell.getNumericCellValue(), 0.0001);
   }
View Full Code Here

            if(i==columnEnd){
                cFields.setCount(cFields.getCacheFieldList().size());
            }
            //General number format
            cf.setNumFmtId(0);
            Cell cell = row.getCell(i);
            cell.setCellType(Cell.CELL_TYPE_STRING);
            cf.setName(row.getCell(i).getStringCellValue());
            cf.addNewSharedItems();
        }
    }
View Full Code Here

        } else {
            dataFields = pivotTableDefinition.addNewDataFields();
        }
        CTDataField dataField = dataFields.addNewDataField();
        dataField.setSubtotal(STDataConsolidateFunction.Enum.forInt(function.getValue()));
        Cell cell = getDataSheet().getRow(pivotArea.getFirstCell().getRow()).getCell(columnIndex);
        cell.setCellType(Cell.CELL_TYPE_STRING);
        dataField.setName(function.getName());
        dataField.setFld(columnIndex);
        dataFields.setCount(dataFields.getDataFieldList().size());
    }
View Full Code Here

            }
            int limit = sheet.getLastRowNum();
            boolean isDuplicate = false;
            for (int i = 1; i < limit+1; i++) {
                Row row = sheet.getRow(i);
                Cell cell = row.getCell(0);
                String userName = cell.getStringCellValue();
                if (!userStore.isExistingUser(userName)) {
                    userStore.addUser(userName, password, null, null, null, true);
                } else {
                    isDuplicate = true;
                }
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.