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);
}
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);
}
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;
}
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());
}
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);
}
Aggregations