Example usage for org.apache.poi.hssf.usermodel HSSFCell getCellStyle

List of usage examples for org.apache.poi.hssf.usermodel HSSFCell getCellStyle

Introduction

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

Prototype

public HSSFCellStyle getCellStyle() 

Source Link

Document

get the style for the cell.

Usage

From source file:org.pentaho.reporting.engine.classic.core.bugs.Prd5391IT.java

License:Open Source License

@Test
public void testSlowExport() throws ResourceException, ReportProcessingException, IOException {
    // This establishes a baseline for the second test using the slow export.

    final MasterReport report = DebugReportRunner.parseLocalReport("Prd-5391.prpt", Prd5391IT.class);
    final ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ExcelReportUtil.createXLS(report, bout);

    final HSSFWorkbook wb = new HSSFWorkbook(new ByteArrayInputStream(bout.toByteArray()));
    final HSSFSheet sheetAt = wb.getSheetAt(0);
    final HSSFRow row = sheetAt.getRow(0);
    final HSSFCell cell0 = row.getCell(0);

    // assert that we are in the correct export type ..
    final HSSFCellStyle cellStyle = cell0.getCellStyle();
    final HSSFColor fillBackgroundColorColor = cellStyle.getFillBackgroundColorColor();
    final HSSFColor fillForegroundColorColor = cellStyle.getFillForegroundColorColor();
    Assert.assertEquals("0:0:0", fillBackgroundColorColor.getHexString());
    Assert.assertEquals("FFFF:8080:8080", fillForegroundColorColor.getHexString());

    HSSFFont font = cellStyle.getFont(wb);
    Assert.assertEquals("Times New Roman", font.getFontName());
}

From source file:org.pentaho.reporting.engine.classic.core.bugs.Prd5391IT.java

License:Open Source License

@Test
public void testFastExport() throws ResourceException, ReportProcessingException, IOException {
    // This establishes a baseline for the second test using the slow export.

    final MasterReport report = DebugReportRunner.parseLocalReport("Prd-5391.prpt", Prd5391IT.class);
    final ByteArrayOutputStream bout = new ByteArrayOutputStream();
    FastExcelReportUtil.processXls(report, bout);

    final HSSFWorkbook wb = new HSSFWorkbook(new ByteArrayInputStream(bout.toByteArray()));
    final HSSFSheet sheetAt = wb.getSheetAt(0);
    final HSSFRow row = sheetAt.getRow(0);
    final HSSFCell cell0 = row.getCell(0);

    // assert that we are in the correct export type ..
    final HSSFCellStyle cellStyle = cell0.getCellStyle();
    final HSSFColor fillBackgroundColorColor = cellStyle.getFillBackgroundColorColor();
    final HSSFColor fillForegroundColorColor = cellStyle.getFillForegroundColorColor();
    Assert.assertEquals("0:0:0", fillBackgroundColorColor.getHexString());
    Assert.assertEquals("FFFF:8080:8080", fillForegroundColorColor.getHexString());

    HSSFFont font = cellStyle.getFont(wb);
    Assert.assertEquals("Times New Roman", font.getFontName());
}

From source file:org.seasar.dbflute.helper.io.xls.DfTableXlsReader.java

License:Apache License

protected boolean isCellBase64Formatted(HSSFCell cell) {
    final HSSFCellStyle cs = cell.getCellStyle();
    final short dfNum = cs.getDataFormat();
    return DfDataSetConstants.BASE64_FORMAT.equals(_dataFormat.getFormat(dfNum));
}

From source file:org.seasar.dbflute.helper.io.xls.DfTableXlsReader.java

License:Apache License

protected boolean isCellDateFormatted(HSSFCell cell) {
    final HSSFCellStyle cs = cell.getCellStyle();
    final short dfNum = cs.getDataFormat();
    final String format = _dataFormat.getFormat(dfNum);
    if (format == null || format.length() == 0) {
        return false;
    }//from   ww w . j a  v a  2  s  . c om
    if (format.indexOf('/') > 0 || format.indexOf('y') > 0 || format.indexOf('m') > 0
            || format.indexOf('d') > 0) {
        return true;
    }
    return false;
}

From source file:org.seasar.dbflute.helper.io.xls.DfXlsReader.java

License:Apache License

protected boolean isCellBase64Formatted(HSSFCell cell) {
    HSSFCellStyle cs = cell.getCellStyle();
    short dfNum = cs.getDataFormat();
    return DfDataSetConstants.BASE64_FORMAT.equals(_dataFormat.getFormat(dfNum));
}

From source file:org.seasar.dbflute.helper.io.xls.DfXlsReader.java

License:Apache License

protected boolean isCellDateFormatted(HSSFCell cell) {
    HSSFCellStyle cs = cell.getCellStyle();
    short dfNum = cs.getDataFormat();
    String format = _dataFormat.getFormat(dfNum);
    if (format == null || format.length() == 0) {
        return false;
    }/*from  w  w w  .j a v  a  2 s  .com*/
    if (format.indexOf('/') > 0 || format.indexOf('y') > 0 || format.indexOf('m') > 0
            || format.indexOf('d') > 0) {
        return true;
    }
    return false;
}

From source file:org.seasar.extension.dataset.impl.XlsReader.java

License:Apache License

/**
 * ?Base64???????????/*from   www.java2  s  . c om*/
 * 
 * @param cell
 *            
 * @return ?Base64????????
 */
public boolean isCellBase64Formatted(HSSFCell cell) {
    HSSFCellStyle cs = cell.getCellStyle();
    short dfNum = cs.getDataFormat();
    return BASE64_FORMAT.equals(dataFormat.getFormat(dfNum));
}

From source file:org.seasar.extension.dataset.impl.XlsReader.java

License:Apache License

/**
 * ?????????//from   w  ww . ja  v a 2s . co  m
 * 
 * @param cell
 *            
 * @return ??????
 */
public boolean isCellDateFormatted(HSSFCell cell) {
    HSSFCellStyle cs = cell.getCellStyle();
    short dfNum = cs.getDataFormat();
    String format = dataFormat.getFormat(dfNum);
    if (StringUtil.isEmpty(format)) {
        return false;
    }
    if (format.indexOf('/') > 0 || format.indexOf('y') > 0 || format.indexOf('m') > 0
            || format.indexOf('d') > 0) {
        return true;
    }
    return false;
}

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  a  va  2 s  .  c  o m*/
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;

    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/*from w  w  w .j av a2 s . co  m*/
            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;
}