Example usage for org.apache.poi.hssf.usermodel HSSFCellStyle getFillPattern

List of usage examples for org.apache.poi.hssf.usermodel HSSFCellStyle getFillPattern

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFCellStyle getFillPattern.

Prototype

@Override
    public FillPatternType getFillPattern() 

Source Link

Usage

From source file:org.orbeon.oxf.util.XLSUtils.java

License:Open Source License

public static void copyCell(HSSFWorkbook workbook, HSSFCell destination, HSSFCell source) {

    // Copy cell content
    destination.setCellType(source.getCellType());
    switch (source.getCellType()) {
    case HSSFCell.CELL_TYPE_BOOLEAN:
        destination.setCellValue(source.getBooleanCellValue());
        break;/* w w w  .j  a  va 2  s  . c o m*/
    case HSSFCell.CELL_TYPE_FORMULA:
    case HSSFCell.CELL_TYPE_STRING:
        destination.setCellValue(source.getStringCellValue());
        break;
    case HSSFCell.CELL_TYPE_NUMERIC:
        destination.setCellValue(source.getNumericCellValue());
        break;
    }

    // Copy cell style
    HSSFCellStyle sourceCellStyle = source.getCellStyle();
    HSSFCellStyle destinationCellStyle = workbook.createCellStyle();
    destinationCellStyle.setAlignment(sourceCellStyle.getAlignment());
    destinationCellStyle.setBorderBottom(sourceCellStyle.getBorderBottom());
    destinationCellStyle.setBorderLeft(sourceCellStyle.getBorderLeft());
    destinationCellStyle.setBorderRight(sourceCellStyle.getBorderRight());
    destinationCellStyle.setBorderTop(sourceCellStyle.getBorderTop());
    destinationCellStyle.setBottomBorderColor(sourceCellStyle.getBottomBorderColor());
    destinationCellStyle.setDataFormat(sourceCellStyle.getDataFormat());
    destinationCellStyle.setFillBackgroundColor(sourceCellStyle.getFillForegroundColor());
    destinationCellStyle.setFillForegroundColor(sourceCellStyle.getFillForegroundColor());
    destinationCellStyle.setFillPattern(sourceCellStyle.getFillPattern());
    destinationCellStyle.setFont(workbook.getFontAt(sourceCellStyle.getFontIndex()));
    destinationCellStyle.setHidden(sourceCellStyle.getHidden());
    destinationCellStyle.setIndention(sourceCellStyle.getIndention());
    destinationCellStyle.setLeftBorderColor(sourceCellStyle.getLeftBorderColor());
    destinationCellStyle.setLocked(sourceCellStyle.getLocked());
    destinationCellStyle.setRightBorderColor(sourceCellStyle.getRightBorderColor());
    destinationCellStyle.setRotation(sourceCellStyle.getRotation());
    destinationCellStyle.setTopBorderColor(sourceCellStyle.getTopBorderColor());
    destinationCellStyle.setVerticalAlignment(sourceCellStyle.getVerticalAlignment());
    destinationCellStyle.setWrapText(sourceCellStyle.getWrapText());
    destination.setCellStyle(destinationCellStyle);
}

From source file:poi.hssf.view.SVTableCellEditor.java

License:Apache License

/**
 *  Gets the tableCellEditorComponent attribute of the SVTableCellEditor object
 *
 * @return             The tableCellEditorComponent value
 *///w  ww  .j  av a2 s .  c  om
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row,
        int column) {
    System.out.println("GetTableCellEditorComponent");
    HSSFCell cell = (HSSFCell) value;
    if (cell != null) {
        HSSFCellStyle style = cell.getCellStyle();
        HSSFFont f = wb.getFontAt(style.getFontIndex());
        boolean isbold = f.getBoldweight() > HSSFFont.BOLDWEIGHT_NORMAL;
        boolean isitalics = f.getItalic();

        int fontstyle = Font.PLAIN;

        if (isbold)
            fontstyle = Font.BOLD;
        if (isitalics)
            fontstyle = fontstyle | Font.ITALIC;

        int fontheight = f.getFontHeightInPoints();
        if (fontheight == 9)
            fontheight = 10; //fix for stupid ol Windows

        Font font = new Font(f.getFontName(), fontstyle, fontheight);
        editor.setFont(font);

        if (style.getFillPattern() == HSSFCellStyle.SOLID_FOREGROUND) {
            editor.setBackground(getAWTColor(style.getFillForegroundColor(), white));
        } else
            editor.setBackground(white);

        editor.setForeground(getAWTColor(f.getColor(), black));

        //Set the value that is rendered for the cell
        switch (cell.getCellType()) {
        case HSSFCell.CELL_TYPE_BLANK:
            editor.setText("");
            break;
        case HSSFCell.CELL_TYPE_BOOLEAN:
            if (cell.getBooleanCellValue()) {
                editor.setText("true");
            } else {
                editor.setText("false");
            }
            break;
        case HSSFCell.CELL_TYPE_NUMERIC:
            editor.setText(Double.toString(cell.getNumericCellValue()));
            break;
        case HSSFCell.CELL_TYPE_STRING:
            editor.setText(cell.getRichStringCellValue().getString());
            break;
        case HSSFCell.CELL_TYPE_FORMULA:
        default:
            editor.setText("?");
        }
        switch (style.getAlignment()) {
        case HSSFCellStyle.ALIGN_LEFT:
        case HSSFCellStyle.ALIGN_JUSTIFY:
        case HSSFCellStyle.ALIGN_FILL:
            editor.setHorizontalAlignment(SwingConstants.LEFT);
            break;
        case HSSFCellStyle.ALIGN_CENTER:
        case HSSFCellStyle.ALIGN_CENTER_SELECTION:
            editor.setHorizontalAlignment(SwingConstants.CENTER);
            break;
        case HSSFCellStyle.ALIGN_GENERAL:
        case HSSFCellStyle.ALIGN_RIGHT:
            editor.setHorizontalAlignment(SwingConstants.RIGHT);
            break;
        default:
            editor.setHorizontalAlignment(SwingConstants.LEFT);
            break;
        }

    }
    return editor;
}

From source file:poi.hssf.view.SVTableCellRenderer.java

License:Apache License

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    boolean isBorderSet = false;

    //If the JTables default cell renderer has been setup correctly the
    //value will be the HSSFCell that we are trying to render
    HSSFCell c = (HSSFCell) value;/*from   w w w  .ja  v  a  2 s  .  c om*/

    if (c != null) {
        HSSFCellStyle s = c.getCellStyle();
        HSSFFont f = wb.getFontAt(s.getFontIndex());
        setFont(SVTableUtils.makeFont(f));

        if (s.getFillPattern() == HSSFCellStyle.SOLID_FOREGROUND) {
            setBackground(SVTableUtils.getAWTColor(s.getFillForegroundColor(), SVTableUtils.white));
        } else
            setBackground(SVTableUtils.white);

        setForeground(SVTableUtils.getAWTColor(f.getColor(), SVTableUtils.black));

        cellBorder.setBorder(SVTableUtils.getAWTColor(s.getTopBorderColor(), SVTableUtils.black),
                SVTableUtils.getAWTColor(s.getRightBorderColor(), SVTableUtils.black),
                SVTableUtils.getAWTColor(s.getBottomBorderColor(), SVTableUtils.black),
                SVTableUtils.getAWTColor(s.getLeftBorderColor(), SVTableUtils.black), s.getBorderTop(),
                s.getBorderRight(), s.getBorderBottom(), s.getBorderLeft(), hasFocus);
        setBorder(cellBorder);
        isBorderSet = true;

        //Set the value that is rendered for the cell
        switch (c.getCellType()) {
        case HSSFCell.CELL_TYPE_BLANK:
            setValue("");
            break;
        case HSSFCell.CELL_TYPE_BOOLEAN:
            if (c.getBooleanCellValue()) {
                setValue("true");
            } else {
                setValue("false");
            }
            break;
        case HSSFCell.CELL_TYPE_NUMERIC:
            short format = s.getDataFormat();
            double numericValue = c.getNumericCellValue();
            if (cellFormatter.useRedColor(format, numericValue))
                setForeground(Color.red);
            else
                setForeground(null);
            setValue(cellFormatter.format(format, c.getNumericCellValue()));
            break;
        case HSSFCell.CELL_TYPE_STRING:
            setValue(c.getRichStringCellValue().getString());
            break;
        case HSSFCell.CELL_TYPE_FORMULA:
        default:
            setValue("?");
        }
        //Set the text alignment of the cell
        switch (s.getAlignment()) {
        case HSSFCellStyle.ALIGN_LEFT:
        case HSSFCellStyle.ALIGN_JUSTIFY:
        case HSSFCellStyle.ALIGN_FILL:
            setHorizontalAlignment(SwingConstants.LEFT);
            break;
        case HSSFCellStyle.ALIGN_CENTER:
        case HSSFCellStyle.ALIGN_CENTER_SELECTION:
            setHorizontalAlignment(SwingConstants.CENTER);
            break;
        case HSSFCellStyle.ALIGN_GENERAL:
        case HSSFCellStyle.ALIGN_RIGHT:
            setHorizontalAlignment(SwingConstants.RIGHT);
            break;
        default:
            setHorizontalAlignment(SwingConstants.LEFT);
            break;
        }
    } else {
        setValue("");
        setBackground(SVTableUtils.white);
    }

    if (hasFocus) {
        if (!isBorderSet) {
            //This is the border to paint when there is no border
            //and the cell has focus
            cellBorder.setBorder(SVTableUtils.black, SVTableUtils.black, SVTableUtils.black, SVTableUtils.black,
                    HSSFCellStyle.BORDER_NONE, HSSFCellStyle.BORDER_NONE, HSSFCellStyle.BORDER_NONE,
                    HSSFCellStyle.BORDER_NONE, isSelected);
            setBorder(cellBorder);
        }
        if (table.isCellEditable(row, column)) {
            setForeground(UIManager.getColor("Table.focusCellForeground"));
            setBackground(UIManager.getColor("Table.focusCellBackground"));
        }
    } else if (!isBorderSet) {
        setBorder(noFocusBorder);
    }

    // ---- begin optimization to avoid painting background ----
    Color back = getBackground();
    boolean colorMatch = (back != null) && (back.equals(table.getBackground())) && table.isOpaque();
    setOpaque(!colorMatch);
    // ---- end optimization to aviod painting background ----
    return this;
}

From source file:ru.spb.nicetu.tableviewer.server.HSSFHtmlHelper.java

License:Apache License

public void colorStyles(CellStyle style, Formatter out, boolean isBuiltIn) {
    HSSFCellStyle cs = (HSSFCellStyle) style;
    if (!isBuiltIn)
        out.format("  ");
    out.format("/* fill pattern = %d */", cs.getFillPattern());
    if (!isBuiltIn)
        out.format("%n");
    styleColor(out, "background-color", cs.getFillForegroundColor(), isBuiltIn);
    styleColor(out, "color", cs.getFont(wb).getColor(), isBuiltIn);
    styleColor(out, "border-left-color", cs.getLeftBorderColor(), isBuiltIn);
    styleColor(out, "border-right-color", cs.getRightBorderColor(), isBuiltIn);
    styleColor(out, "border-top-color", cs.getTopBorderColor(), isBuiltIn);
    styleColor(out, "border-bottom-color", cs.getBottomBorderColor(), isBuiltIn);
}