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