Examples of CellStyle


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

            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);
        }
View Full Code Here

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

        {
          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

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

    {
      // Read in the styles ...
      final short predefinedStyles = workbook.getNumCellStyles();
      for (short i = 0; i < predefinedStyles; i++)
      {
        final CellStyle cellStyleAt = workbook.getCellStyleAt(i);
        this.styleCache.put(new HSSFCellStyleKey(cellStyleAt), cellStyleAt);
      }
    }
  }
View Full Code Here

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

            "HSSFCellStyleProducer will not create more styles. New cells will not have any style.");
        return null;
      }
    }
   
    final CellStyle hssfCellStyle = workbook.createCellStyle();
    if (element != null)
    {
      hssfCellStyle.setAlignment(styleKey.getHorizontalAlignment());
      hssfCellStyle.setVerticalAlignment(styleKey.getVerticalAlignment());
      hssfCellStyle.setFont(workbook.getFontAt(styleKey.getFont()));
      hssfCellStyle.setWrapText(styleKey.isWrapText());
      hssfCellStyle.setDataFormat(styleKey.getDataStyle());
    }
    if (bg != null)
    {
      if (hssfCellStyle instanceof XSSFCellStyle)
      {
        final XSSFCellStyle xssfCellStyle = (XSSFCellStyle) hssfCellStyle;
        if (BorderStyle.NONE.equals(bg.getBottom().getBorderStyle()) == false)
        {
          hssfCellStyle.setBorderBottom(styleKey.getBorderStrokeBottom());
          xssfCellStyle.setBorderColor(XSSFCellBorder.BorderSide.BOTTOM,
              new XSSFColor(styleKey.getExtendedColorBottom()));
        }
        if (BorderStyle.NONE.equals(bg.getTop().getBorderStyle()) == false)
        {
          hssfCellStyle.setBorderTop(styleKey.getBorderStrokeTop());
          xssfCellStyle.setBorderColor(XSSFCellBorder.BorderSide.TOP,
              new XSSFColor(styleKey.getExtendedColorTop()));
        }
        if (BorderStyle.NONE.equals(bg.getLeft().getBorderStyle()) == false)
        {
          hssfCellStyle.setBorderLeft(styleKey.getBorderStrokeLeft());
          xssfCellStyle.setBorderColor(XSSFCellBorder.BorderSide.LEFT,
              new XSSFColor(styleKey.getExtendedColorLeft()));
        }
        if (BorderStyle.NONE.equals(bg.getRight().getBorderStyle()) == false)
        {
          hssfCellStyle.setBorderRight(styleKey.getBorderStrokeRight());
          xssfCellStyle.setBorderColor(XSSFCellBorder.BorderSide.RIGHT,
              new XSSFColor(styleKey.getExtendedColorRight()));
        }
        if (bg.getBackgroundColor() != null)
        {
          xssfCellStyle.setFillForegroundColor(new XSSFColor(styleKey.getExtendedColor()));
          hssfCellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        }
      }
      else
      {
        if (BorderStyle.NONE.equals(bg.getBottom().getBorderStyle()) == false)
        {
          hssfCellStyle.setBorderBottom(styleKey.getBorderStrokeBottom());
          hssfCellStyle.setBottomBorderColor(styleKey.getColorBottom());
        }
        if (BorderStyle.NONE.equals(bg.getTop().getBorderStyle()) == false)
        {
          hssfCellStyle.setBorderTop(styleKey.getBorderStrokeTop());
          hssfCellStyle.setTopBorderColor(styleKey.getColorTop());
        }
        if (BorderStyle.NONE.equals(bg.getLeft().getBorderStyle()) == false)
        {
          hssfCellStyle.setBorderLeft(styleKey.getBorderStrokeLeft());
          hssfCellStyle.setLeftBorderColor(styleKey.getColorLeft());
        }
        if (BorderStyle.NONE.equals(bg.getRight().getBorderStyle()) == false)
        {
          hssfCellStyle.setBorderRight(styleKey.getBorderStrokeRight());
          hssfCellStyle.setRightBorderColor(styleKey.getColorRight());
        }
        if (bg.getBackgroundColor() != null)
        {
          hssfCellStyle.setFillForegroundColor(styleKey.getColor());
          hssfCellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        }
      }
    }

View Full Code Here

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

       // Check all the colours
       for(int sn=0; sn<wb.getNumberOfSheets(); sn++) {
          Sheet s = wb.getSheetAt(sn);
          for(Row r : s) {
             for(Cell c : r) {
                CellStyle cs = c.getCellStyle();
                if(cs != null) {
                   cs.getFillForegroundColor();
                }
             }
          }
       }
      
View Full Code Here

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

       richTextString.applyFont(font3);
       richTextString.applyFont(0, 3, font1);
       cell.setCellValue(richTextString);

       // To enable newlines you need set a cell styles with wrap=true
       CellStyle cs = wb.createCellStyle();
       cs.setWrapText(true);
       cell.setCellStyle(cs);

       // Check the text has the
       assertEquals(text, cell.getStringCellValue());
      
View Full Code Here

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

     */
    public void test51037() throws Exception {
       XSSFWorkbook wb = new XSSFWorkbook();
       XSSFSheet s = wb.createSheet();
      
       CellStyle defaultStyle = wb.getCellStyleAt((short)0);
       assertEquals(0, defaultStyle.getIndex());
      
       CellStyle blueStyle = wb.createCellStyle();
       blueStyle.setFillForegroundColor(IndexedColors.AQUA.getIndex());
       blueStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
       assertEquals(1, blueStyle.getIndex());

       CellStyle pinkStyle = wb.createCellStyle();
       pinkStyle.setFillForegroundColor(IndexedColors.PINK.getIndex());
       pinkStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
       assertEquals(2, pinkStyle.getIndex());

       // Starts empty
       assertEquals(1, s.getCTWorksheet().sizeOfColsArray());
       CTCols cols = s.getCTWorksheet().getColsArray(0);
       assertEquals(0, cols.sizeOfColArray());
      
       // Add some rows and columns
       XSSFRow r1 = s.createRow(0);
       XSSFRow r2 = s.createRow(1);
       r1.createCell(0);
       r1.createCell(2);
       r2.createCell(0);
       r2.createCell(3);
      
       // Check no style is there
       assertEquals(1, s.getCTWorksheet().sizeOfColsArray());
       assertEquals(0, cols.sizeOfColArray());
      
       assertEquals(defaultStyle, s.getColumnStyle(0));
       assertEquals(defaultStyle, s.getColumnStyle(2));
       assertEquals(defaultStyle, s.getColumnStyle(3));
      
      
       // Apply the styles
       s.setDefaultColumnStyle(0, pinkStyle);
       s.setDefaultColumnStyle(3, blueStyle);
      
       // Check
       assertEquals(pinkStyle, s.getColumnStyle(0));
       assertEquals(defaultStyle, s.getColumnStyle(2));
       assertEquals(blueStyle, s.getColumnStyle(3));
      
       assertEquals(1, s.getCTWorksheet().sizeOfColsArray());
       assertEquals(2, cols.sizeOfColArray());
      
       assertEquals(1, cols.getColArray(0).getMin());
       assertEquals(1, cols.getColArray(0).getMax());
       assertEquals(pinkStyle.getIndex(), cols.getColArray(0).getStyle());
      
       assertEquals(4, cols.getColArray(1).getMin());
       assertEquals(4, cols.getColArray(1).getMax());
       assertEquals(blueStyle.getIndex(), cols.getColArray(1).getStyle());
      
      
       // Save, re-load and re-check
       wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
       s = wb.getSheetAt(0);
       defaultStyle = wb.getCellStyleAt(defaultStyle.getIndex());
       blueStyle = wb.getCellStyleAt(blueStyle.getIndex());
       pinkStyle = wb.getCellStyleAt(pinkStyle.getIndex());
      
       assertEquals(pinkStyle, s.getColumnStyle(0));
       assertEquals(defaultStyle, s.getColumnStyle(2));
       assertEquals(blueStyle, s.getColumnStyle(3));
    }
View Full Code Here

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

   * and the setVerticalAlignment() method for vertical alignment of the cell.
   */
  private void createCell(Workbook wb, Row row, int column, String cellValue, short halign, short valign) {
    Cell cell = row.createCell(column);
    cell.setCellValue(cellValue);
    CellStyle cellStyle = wb.createCellStyle();
    cellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
    cellStyle.setBorderTop(CellStyle.BORDER_THIN);
    cellStyle.setBorderRight(CellStyle.BORDER_THIN);
    cellStyle.setBorderLeft(CellStyle.BORDER_THIN);
    cellStyle.setBorderBottom(CellStyle.BORDER_THIN);
    cellStyle.setAlignment(halign);
    cellStyle.setVerticalAlignment(valign);
    cell.setCellStyle(cellStyle);
  }
View Full Code Here

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

    public static Style getCellStyle(Workbook workbook, Cell cell) {
        if (cell == null) {
            return Style.NO_STYLE;
        }
        final CellStyle cellStyle = cell.getCellStyle();

        final short fontIndex = cellStyle.getFontIndex();
        final Font font = workbook.getFontAt(fontIndex);
        final StyleBuilder styleBuilder = new StyleBuilder();

        // Font bold, italic, underline
        if (font.getBoldweight() >= Font.BOLDWEIGHT_BOLD) {
            styleBuilder.bold();
        }
        if (font.getItalic()) {
            styleBuilder.italic();
        }
        if (font.getUnderline() != FontUnderline.NONE.getByteValue()) {
            styleBuilder.underline();
        }

        // Font size
        final Font stdFont = workbook.getFontAt((short) 0);
        final short fontSize = font.getFontHeightInPoints();
        if (stdFont.getFontHeightInPoints() != fontSize) {
            styleBuilder.fontSize(fontSize, SizeUnit.PT);
        }

        // Font color
        final short colorIndex = font.getColor();
        if (font instanceof HSSFFont) {
            if (colorIndex != HSSFFont.COLOR_NORMAL) {
                final HSSFWorkbook wb = (HSSFWorkbook) workbook;
                HSSFColor color = wb.getCustomPalette().getColor(colorIndex);
                if (color != null) {
                    short[] triplet = color.getTriplet();
                    styleBuilder.foreground(triplet);
                }
            }
        } else if (font instanceof XSSFFont) {
            XSSFFont xssfFont = (XSSFFont) font;

            XSSFColor color = xssfFont.getXSSFColor();
            if (color != null) {
                String argbHex = color.getARGBHex();
                if (argbHex != null) {
                    styleBuilder.foreground(argbHex.substring(2));
                }
            }
        } else {
            throw new IllegalStateException("Unexpected font type: " + (font == null ? "null" : font.getClass()) + ")");
        }

        // Background color
        if (cellStyle.getFillPattern() == 1) {
            Color color = cellStyle.getFillForegroundColorColor();
            if (color instanceof HSSFColor) {
                short[] triplet = ((HSSFColor) color).getTriplet();
                if (triplet != null) {
                    styleBuilder.background(triplet);
                }
            } else if (color instanceof XSSFColor) {
                String argb = ((XSSFColor) color).getARGBHex();
                if (argb != null) {
                    styleBuilder.background(argb.substring(2));
                }
            } else {
                throw new IllegalStateException("Unexpected color type: " + (color == null ? "null" : color.getClass()) + ")");
            }
        }

        // alignment
        switch (cellStyle.getAlignment()) {
        case CellStyle.ALIGN_LEFT:
            styleBuilder.leftAligned();
            break;
        case CellStyle.ALIGN_RIGHT:
            styleBuilder.rightAligned();
View Full Code Here

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

                    }
                    if (type == Cell.CELL_TYPE_STRING) {
                        xhtml.characters(cell.getRichStringCellValue()
                                .getString());
                    } else if (type == Cell.CELL_TYPE_NUMERIC) {
                      CellStyle style = cell.getCellStyle();
                      xhtml.characters(
                        formatter.formatRawCellContents(cell.getNumericCellValue(),
                              style.getDataFormat(),
                              style.getDataFormatString()));
                    } else {
                        XSSFCell xc = (XSSFCell) cell;
                        String rawValue = xc.getRawValue();
                        if (rawValue != null) {
                            xhtml.characters(rawValue);
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.