Package org.apache.poi.ss.usermodel

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


  }

  private Cell getCellAt(final short x, final int y)
  {
    final Row row = getRowAt(y);
    final Cell cell = row.getCell(x);
    if (cell != null)
    {
      return cell;
    }
    return row.createCell(x);
View Full Code Here


            // An empty cell .. ignore
            continue;
          }

          // A empty cell with a defined background ..
          final Cell cell = getCellAt(col, row);
          final CellStyle style = cellStyleProducer.createCellStyle(null, background);
          if (style != null)
          {
            cell.setCellStyle(style);
          }
          continue;
        }

        if (content.isCommited() == false)
        {
          throw new InvalidReportStateException("Uncommited content encountered");
        }

        final long contentOffset = contentProducer.getContentOffset(row, col);
        final TableRectangle rectangle = sheetLayout.getTableBounds
            (content.getX(), content.getY() + contentOffset,
                content.getWidth(), content.getHeight(), null);
        if (rectangle.isOrigin(col, row) == false)
        {
          // A spanned cell ..
          continue;
        }

        final int sectionType = contentProducer.getSectionType(row, col);
        final CellBackground realBackground = cellBackgroundProducer.getBackgroundAt
            (logicalPage, sheetLayout,
                rectangle.getX1(), rectangle.getY1(), rectangle.getColumnSpan(), rectangle.getRowSpan(), false, sectionType);

        // export the cell and all content ..

        final Cell cell = getCellAt(col, row);
        final CellStyle style = cellStyleProducer.createCellStyle(content, realBackground);
        if (style != null)
        {
          cell.setCellStyle(style);
        }

        if (applyCellValue(metaData, content, cell, sheetLayout, rectangle, contentOffset))
        {
          mergeCellRegion(rectangle, row, col, sheetLayout, logicalPage, content, contentProducer);
View Full Code Here

        for (int spannedCol = 0; spannedCol < columnSpan; spannedCol += 1)
        {
          final int sectionType = contentProducer.getSectionType(row, col);
          final CellBackground bg = cellBackgroundProducer.getBackgroundAt
              (logicalPage, sheetLayout, rectX + spannedCol, rectY + spannedRow, 1, 1, false, sectionType);
          final Cell regionCell = getCellAt((short) (col + spannedCol), row + spannedRow);
          final CellStyle spannedStyle = cellStyleProducer.createCellStyle(content, bg);
          if (spannedStyle != null)
          {
            regionCell.setCellStyle(spannedStyle);
          }
        }
      }
    }
  }
View Full Code Here

      // Rows and cells
      for (Object rawR : sheet) {
        Row row = (Row) rawR;
        for (Iterator<Cell> ri = row.cellIterator(); ri.hasNext();) {
          Cell cell = ri.next();

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

          }

          // Output the comment in the same cell as the content
          Comment comment = cell.getCellComment();
          if (comment != null) {
            buffy.append(comment.getString().getString()).append(' ');
          }
        }
      }
View Full Code Here

     * @see #getCell(int, org.apache.poi.ss.usermodel.Row.MissingCellPolicy)
     */
    public Cell getCell(int cellnum) {
        if(cellnum < 0) throw new IllegalArgumentException("Cell index must be >= 0");

        Cell cell = cellnum > _maxColumn ? null : _cells[cellnum];

        MissingCellPolicy policy = _sheet.getWorkbook().getMissingCellPolicy();
        if(policy == RETURN_NULL_AND_BLANK) {
            return cell;
        }
        if (policy == RETURN_BLANK_AS_NULL) {
            if (cell == null) return cell;
            if (cell.getCellType() == Cell.CELL_TYPE_BLANK) {
                return null;
            }
            return cell;
        }
        if (policy == CREATE_NULL_AS_BLANK) {
View Full Code Here

     * @see Row#CREATE_NULL_AS_BLANK
     */
    public Cell getCell(int cellnum, MissingCellPolicy policy)
    {
        assert false;
        Cell cell = getCell(cellnum);
        if(policy == RETURN_NULL_AND_BLANK)
        {
            return cell;
        }
        if(policy == RETURN_BLANK_AS_NULL)
        {
            if(cell == null) return cell;
            if(cell.getCellType() == Cell.CELL_TYPE_BLANK)
            {
                return null;
            }
            return cell;
        }
View Full Code Here

        }
        public Cell next() throws NoSuchElementException
        {
            if (hasNext())
            {
                Cell retval=_cells[pos];
                advanceToNext();
                return retval;
            }
            else
            {
View Full Code Here

       for(Workbook wb : wbs) {
          Sheet s = wb.createSheet();
          Row r = s.createRow(0);
         
          // Setup
          Cell cn = r.createCell(0, Cell.CELL_TYPE_NUMERIC);
          cn.setCellValue(1.2);
          Cell cs = r.createCell(1, Cell.CELL_TYPE_STRING);
          cs.setCellValue("Testing");
         
          Cell cfn = r.createCell(2, Cell.CELL_TYPE_FORMULA);
          cfn.setCellFormula("A1")
          Cell cfs = r.createCell(3, Cell.CELL_TYPE_FORMULA);
          cfs.setCellFormula("B1");
         
          FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
          assertEquals(Cell.CELL_TYPE_NUMERIC, fe.evaluate(cfn).getCellType());
          assertEquals(Cell.CELL_TYPE_STRING, fe.evaluate(cfs).getCellType());
          fe.evaluateFormulaCell(cfn);
          fe.evaluateFormulaCell(cfs);
         
          // Now test
          assertEquals(Cell.CELL_TYPE_NUMERIC, cn.getCellType());
          assertEquals(Cell.CELL_TYPE_STRING, cs.getCellType());
          assertEquals(Cell.CELL_TYPE_FORMULA, cfn.getCellType());
          assertEquals(Cell.CELL_TYPE_NUMERIC, cfn.getCachedFormulaResultType());
          assertEquals(Cell.CELL_TYPE_FORMULA, cfs.getCellType());
          assertEquals(Cell.CELL_TYPE_STRING, cfs.getCachedFormulaResultType());
         
          // Different ways of retrieving
          assertEquals(1.2, cn.getNumericCellValue());
          try {
             cn.getRichStringCellValue();
             fail();
          } catch(IllegalStateException e) {}
         
          assertEquals("Testing", cs.getStringCellValue());
          try {
             cs.getNumericCellValue();
             fail();
          } catch(IllegalStateException e) {}
         
          assertEquals(1.2, cfn.getNumericCellValue());
          try {
             cfn.getRichStringCellValue();
             fail();
          } catch(IllegalStateException e) {}
         
          assertEquals("Testing", cfs.getStringCellValue());
          try {
             cfs.getNumericCellValue();
             fail();
          } catch(IllegalStateException e) {}
       }
    }
View Full Code Here

    public void test49783() throws Exception {
        Workbook wb =  XSSFTestDataSamples.openSampleWorkbook("49783.xlsx");
        Sheet sheet = wb.getSheetAt(0);
        FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
        Cell cell;

        cell = sheet.getRow(0).getCell(0);
        assertEquals("#REF!*#REF!", cell.getCellFormula());
        assertEquals(Cell.CELL_TYPE_ERROR, evaluator.evaluateInCell(cell).getCellType());
        assertEquals("#REF!", FormulaError.forInt(cell.getErrorCellValue()).getString());

        Name nm1 = wb.getName("sale_1");
        assertNotNull("name sale_1 should be present", nm1);
        assertEquals("Sheet1!#REF!", nm1.getRefersToFormula());
        Name nm2 = wb.getName("sale_2");
        assertNotNull("name sale_2 should be present", nm2);
        assertEquals("Sheet1!#REF!", nm2.getRefersToFormula());

        cell = sheet.getRow(1).getCell(0);
        assertEquals("sale_1*sale_2", cell.getCellFormula());
        assertEquals(Cell.CELL_TYPE_ERROR, evaluator.evaluateInCell(cell).getCellType());
        assertEquals("#REF!", FormulaError.forInt(cell.getErrorCellValue()).getString());
    }
View Full Code Here

     * Newlines are valid characters in a formula
     */
    public void test50440() throws Exception {
       Workbook wb = XSSFTestDataSamples.openSampleWorkbook("NewlineInFormulas.xlsx");
       Sheet s = wb.getSheetAt(0);
       Cell c = s.getRow(0).getCell(0);
      
       assertEquals("SUM(\n1,2\n)", c.getCellFormula());
       assertEquals(3.0, c.getNumericCellValue());
      
       FormulaEvaluator formulaEvaluator = wb.getCreationHelper().createFormulaEvaluator();
       formulaEvaluator.evaluateFormulaCell(c);
      
       assertEquals("SUM(\n1,2\n)", c.getCellFormula());
       assertEquals(3.0, c.getNumericCellValue());
    }
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.