Search in sources :

Example 1 with CTPatternFill

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

the class XSSFCellStyle method setFillForegroundColor.

/**
    * Set the foreground fill color represented as a {@link XSSFColor} value.
     * <br/>
    * <i>Note: Ensure Foreground color is set prior to background color.</i>
    * @param color the color to use
    * @see #setFillBackgroundColor(org.apache.poi.xssf.usermodel.XSSFColor) )
    */
public void setFillForegroundColor(XSSFColor color) {
    CTFill ct = getCTFill();
    CTPatternFill ptrn = ct.getPatternFill();
    if (color == null) {
        if (ptrn != null && ptrn.isSetFgColor())
            ptrn.unsetFgColor();
    } else {
        if (ptrn == null)
            ptrn = ct.addNewPatternFill();
        ptrn.setFgColor(color.getCTColor());
    }
    addFill(ct);
}
Also used : CTFill(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill) CTPatternFill(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPatternFill)

Example 2 with CTPatternFill

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

the class XSSFCellStyle method setFillPattern.

/**
     * This element is used to specify cell fill information for pattern and solid color cell fills. For solid cell fills (no pattern),
     * foreground color is used is used. For cell fills with patterns specified, then the cell fill color is specified by the background color element.
     *
     * @param pattern the fill pattern to use
     * @see #setFillBackgroundColor(XSSFColor)
     * @see #setFillForegroundColor(XSSFColor)
     * @see org.apache.poi.ss.usermodel.FillPatternType
     */
@Override
public void setFillPattern(FillPatternType pattern) {
    CTFill ct = getCTFill();
    CTPatternFill ctptrn = ct.isSetPatternFill() ? ct.getPatternFill() : ct.addNewPatternFill();
    if (pattern == FillPatternType.NO_FILL && ctptrn.isSetPatternType()) {
        ctptrn.unsetPatternType();
    } else {
        ctptrn.setPatternType(STPatternType.Enum.forInt(pattern.getCode() + 1));
    }
    addFill(ct);
}
Also used : CTFill(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill) CTPatternFill(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPatternFill)

Example 3 with CTPatternFill

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

the class TestXSSFCellFill method testGetNotModifies.

@Test
public void testGetNotModifies() {
    CTFill ctFill = CTFill.Factory.newInstance();
    XSSFCellFill cellFill = new XSSFCellFill(ctFill, null);
    CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
    ctPatternFill.setPatternType(STPatternType.DARK_DOWN);
    assertEquals(8, cellFill.getPatternType().intValue());
}
Also used : CTFill(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill) CTPatternFill(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPatternFill) Test(org.junit.Test)

Example 4 with CTPatternFill

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

the class TestXSSFCellFill method testGetSetPatternType.

@Test
public void testGetSetPatternType() {
    CTFill ctFill = CTFill.Factory.newInstance();
    XSSFCellFill cellFill = new XSSFCellFill(ctFill, null);
    CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
    ctPatternFill.setPatternType(STPatternType.SOLID);
    assertEquals(FillPatternType.SOLID_FOREGROUND.ordinal(), cellFill.getPatternType().intValue() - 1);
}
Also used : CTFill(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill) CTPatternFill(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPatternFill) Test(org.junit.Test)

Example 5 with CTPatternFill

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

the class XSSFCellFill method setFillForegroundColor.

/**
     * Set the foreground fill color as a indexed color value
     *
     * @param index - the color to use
     */
public void setFillForegroundColor(int index) {
    CTPatternFill ptrn = ensureCTPatternFill();
    CTColor ctColor = ptrn.isSetFgColor() ? ptrn.getFgColor() : ptrn.addNewFgColor();
    ctColor.setIndexed(index);
}
Also used : CTPatternFill(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPatternFill) CTColor(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor)

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