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

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

Introduction

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

Prototype

@Override
    public HSSFColor getFillBackgroundColorColor() 

Source Link

Usage

From source file:com.report.excel.ExcelToHtmlConverter.java

License:Apache License

protected String buildStyle(HSSFWorkbook workbook, HSSFCellStyle cellStyle) {
    StringBuilder style = new StringBuilder();

    style.append("white-space:pre-wrap;");
    ExcelToHtmlUtils.appendAlign(style, cellStyle.getAlignment());

    if (cellStyle.getFillPattern() == 0) {
        // no fill
    } else if (cellStyle.getFillPattern() == 1) {
        final HSSFColor foregroundColor = cellStyle.getFillForegroundColorColor();
        if (foregroundColor != null)
            style.append("background-color:" + ExcelToHtmlUtils.getColor(foregroundColor) + ";");
    } else {//from w ww.j ava 2 s  . c om
        final HSSFColor backgroundColor = cellStyle.getFillBackgroundColorColor();
        if (backgroundColor != null)
            style.append("background-color:" + ExcelToHtmlUtils.getColor(backgroundColor) + ";");
    }

    buildStyle_border(workbook, style, "top", cellStyle.getBorderTop(), cellStyle.getTopBorderColor());
    buildStyle_border(workbook, style, "right", cellStyle.getBorderRight(), cellStyle.getRightBorderColor());
    buildStyle_border(workbook, style, "bottom", cellStyle.getBorderBottom(), cellStyle.getBottomBorderColor());
    buildStyle_border(workbook, style, "left", cellStyle.getBorderLeft(), cellStyle.getLeftBorderColor());

    HSSFFont font = cellStyle.getFont(workbook);
    buildStyle_font(workbook, style, font);

    return style.toString();
}

From source file:com.vaadin.addon.spreadsheet.HSSFColorConverter.java

License:Open Source License

@Override
public void colorStyles(final CellStyle cellStyle, final StringBuilder sb) {
    HSSFCellStyle cs = (HSSFCellStyle) cellStyle;
    // TODO Fill pattern not supported
    // out.format("  /* fill pattern = %d */%n", cs.getFillPattern());
    short fillForegroundColor = cs.getFillForegroundColor();
    short fillBackgroundColor = cs.getFillBackgroundColor();

    String backgroundColor = null;
    HSSFColor fillForegroundColorColor = cs.getFillForegroundColorColor();
    if (fillForegroundColorColor != null && fillForegroundColor != HSSFColor.AUTOMATIC.index) {
        backgroundColor = styleColor(fillForegroundColor);
    } else {//from  w ww  .  ja v a  2 s . c  om
        HSSFColor fillBackgroundColorColor = cs.getFillBackgroundColorColor();
        if (fillBackgroundColorColor != null && fillBackgroundColor != HSSFColor.AUTOMATIC.index) {
            backgroundColor = styleColor(fillBackgroundColor);
        }
    }
    if (backgroundColor != null && !backgroundColor.equals(defaultBackgroundColor)) {
        sb.append("background-color:");
        sb.append(backgroundColor);
    }

    String color = styleColor(cs.getFont(wb).getColor());
    if (color != null && !color.equals(defaultColor)) {
        sb.append("color:");
        sb.append(color);
    }

}

From source file:com.vaadin.addon.spreadsheet.HSSFColorConverter.java

License:Open Source License

@Override
public boolean hasBackgroundColor(CellStyle cellStyle) {
    HSSFCellStyle cs = (HSSFCellStyle) cellStyle;
    short fillForegroundColor = cs.getFillForegroundColor();
    short fillBackgroundColor = cs.getFillBackgroundColor();

    HSSFColor fillForegroundColorColor = cs.getFillForegroundColorColor();
    if (fillForegroundColorColor != null && fillForegroundColor != HSSFColor.AUTOMATIC.index) {
        return true;
    } else {//from  w w w .ja  v a2  s  .  co m
        HSSFColor fillBackgroundColorColor = cs.getFillBackgroundColorColor();
        if (fillBackgroundColorColor != null && fillBackgroundColor != HSSFColor.AUTOMATIC.index) {
            return true;
        }
    }
    return false;
}

From source file:com.wangzhu.poi.ExcelToHtmlConverter.java

License:Apache License

protected String buildStyle(HSSFWorkbook workbook, HSSFCellStyle cellStyle) {
    StringBuffer style = new StringBuffer();

    style.append("white-space:pre-wrap;");
    ExcelToHtmlUtils.appendAlign(style, cellStyle.getAlignment());

    if (cellStyle.getFillPattern() == 0) {
        // no fill
    } else if (cellStyle.getFillPattern() == 1) {
        final HSSFColor foregroundColor = cellStyle.getFillForegroundColorColor();
        if (foregroundColor != null) {
            style.append("background-color:" + AbstractExcelUtils.getColor(foregroundColor) + ";");
        }// www. j  a  v a2  s . c  om
    } else {
        final HSSFColor backgroundColor = cellStyle.getFillBackgroundColorColor();
        if (backgroundColor != null) {
            style.append("background-color:" + AbstractExcelUtils.getColor(backgroundColor) + ";");
        }
    }

    this.buildStyle_border(workbook, style, "top", cellStyle.getBorderTop(), cellStyle.getTopBorderColor());
    this.buildStyle_border(workbook, style, "right", cellStyle.getBorderRight(),
            cellStyle.getRightBorderColor());
    this.buildStyle_border(workbook, style, "bottom", cellStyle.getBorderBottom(),
            cellStyle.getBottomBorderColor());
    this.buildStyle_border(workbook, style, "left", cellStyle.getBorderLeft(), cellStyle.getLeftBorderColor());

    HSSFFont font = cellStyle.getFont(workbook);
    this.buildStyle_font(workbook, style, font);

    return style.toString();
}

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

License:Open Source License

public void testBug() throws ResourceException, IOException, ReportProcessingException {
    final MasterReport report = DebugReportRunner.parseGoldenSampleReport("Prd-3889.prpt");
    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();
    assertEquals("0:0:0", fillBackgroundColorColor.getHexString());
    assertEquals("FFFF:FFFF:9999", fillForegroundColorColor.getHexString());

    // assert that there are no extra columns ..
    final HSSFRow row8 = sheetAt.getRow(7);
    assertNull(row8);//ww w.j av  a  2s . com

}

From source file:org.pentaho.reporting.engine.classic.core.bugs.Prd5391.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", Prd5391.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.Prd5391.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", Prd5391.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.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());
}