Search in sources :

Example 1 with CTFill

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill 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 CTFill

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill 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 CTFill

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

the class XSSFCellStyle method getCTFill.

/**
     * Get a <b>copy</b> of the currently used CTFill, if none is used, return a new instance.
     */
private CTFill getCTFill() {
    CTFill ct;
    // bug 56295: handle missing applyFill attribute as "true" because Excel does as well
    if (!_cellXf.isSetApplyFill() || _cellXf.getApplyFill()) {
        int fillIndex = (int) _cellXf.getFillId();
        XSSFCellFill cf = _stylesSource.getFillAt(fillIndex);
        ct = (CTFill) cf.getCTFill().copy();
    } else {
        ct = CTFill.Factory.newInstance();
    }
    return ct;
}
Also used : CTFill(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill) XSSFCellFill(org.apache.poi.xssf.usermodel.extensions.XSSFCellFill)

Example 4 with CTFill

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill 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 5 with CTFill

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill 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)

Aggregations

CTFill (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill)11 CTPatternFill (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPatternFill)7 Test (org.junit.Test)6 CTColor (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor)2 POIXMLException (org.apache.poi.POIXMLException)1 XSSFCellFill (org.apache.poi.xssf.usermodel.extensions.XSSFCellFill)1 XmlException (org.apache.xmlbeans.XmlException)1 CTBorder (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder)1 CTFont (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont)1