Search in sources :

Example 11 with CTPatternFill

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPatternFill in project poi by apache.

the class XSSFCellFill method setFillBackgroundColor.

/**
     * Set the background fill color represented as a indexed color value.
     *
     * @param index
     */
public void setFillBackgroundColor(int index) {
    CTPatternFill ptrn = ensureCTPatternFill();
    CTColor ctColor = ptrn.isSetBgColor() ? ptrn.getBgColor() : ptrn.addNewBgColor();
    ctColor.setIndexed(index);
}
Also used : CTPatternFill(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPatternFill) CTColor(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor)

Example 12 with CTPatternFill

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPatternFill in project poi by apache.

the class XSSFCellStyle method setFillBackgroundColor.

/**
     * Set the background fill color represented as a {@link XSSFColor} value.
     * <p>
     * For example:
     * <pre>
     * cs.setFillPattern(XSSFCellStyle.FINE_DOTS );
     * cs.setFillBackgroundXSSFColor(new XSSFColor(java.awt.Color.RED));
     * </pre>
     * optionally a Foreground and background fill can be applied:
     * <i>Note: Ensure Foreground color is set prior to background</i>
     * <pre>
     * cs.setFillPattern(XSSFCellStyle.FINE_DOTS );
     * cs.setFillForegroundColor(new XSSFColor(java.awt.Color.BLUE));
     * cs.setFillBackgroundColor(new XSSFColor(java.awt.Color.GREEN));
     * </pre>
     * or, for the special case of SOLID_FILL:
     * <pre>
     * cs.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND );
     * cs.setFillForegroundColor(new XSSFColor(java.awt.Color.GREEN));
     * </pre>
     * It is necessary to set the fill style in order
     * for the color to be shown in the cell.
     *
     * @param color - the color to use
     */
public void setFillBackgroundColor(XSSFColor color) {
    CTFill ct = getCTFill();
    CTPatternFill ptrn = ct.getPatternFill();
    if (color == null) {
        if (ptrn != null && ptrn.isSetBgColor())
            ptrn.unsetBgColor();
    } else {
        if (ptrn == null)
            ptrn = ct.addNewPatternFill();
        ptrn.setBgColor(color.getCTColor());
    }
    addFill(ct);
}
Also used : CTFill(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill) CTPatternFill(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPatternFill)

Example 13 with CTPatternFill

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPatternFill in project poi by apache.

the class TestXSSFCellFill method testGetFillBackgroundColor.

@Test
public void testGetFillBackgroundColor() {
    CTFill ctFill = CTFill.Factory.newInstance();
    XSSFCellFill cellFill = new XSSFCellFill(ctFill, null);
    CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
    CTColor bgColor = ctPatternFill.addNewBgColor();
    assertNotNull(cellFill.getFillBackgroundColor());
    bgColor.setIndexed(2);
    assertEquals(2, cellFill.getFillBackgroundColor().getIndexed());
}
Also used : CTFill(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill) CTPatternFill(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPatternFill) CTColor(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor) Test(org.junit.Test)

Example 14 with CTPatternFill

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPatternFill in project poi by apache.

the class TestXSSFCellFill method testGetFillForegroundColor.

@Test
public void testGetFillForegroundColor() {
    CTFill ctFill = CTFill.Factory.newInstance();
    XSSFCellFill cellFill = new XSSFCellFill(ctFill, null);
    CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
    CTColor fgColor = ctPatternFill.addNewFgColor();
    assertNotNull(cellFill.getFillForegroundColor());
    fgColor.setIndexed(8);
    assertEquals(8, cellFill.getFillForegroundColor().getIndexed());
}
Also used : CTFill(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill) CTPatternFill(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPatternFill) CTColor(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor) Test(org.junit.Test)

Aggregations

CTPatternFill (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPatternFill)14 CTFill (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill)7 CTColor (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor)6 Test (org.junit.Test)4 XSSFColor (org.apache.poi.xssf.usermodel.XSSFColor)2