use of org.apache.poi.xssf.usermodel.extensions.XSSFCellFill in project poi by apache.
the class TestXSSFCellStyle method setUp.
@Before
public void setUp() {
stylesTable = new StylesTable();
ctStylesheet = stylesTable.getCTStylesheet();
ctBorderA = CTBorder.Factory.newInstance();
XSSFCellBorder borderA = new XSSFCellBorder(ctBorderA);
long borderId = stylesTable.putBorder(borderA);
assertEquals(1, borderId);
XSSFCellBorder borderB = new XSSFCellBorder();
assertEquals(1, stylesTable.putBorder(borderB));
ctFill = CTFill.Factory.newInstance();
XSSFCellFill fill = new XSSFCellFill(ctFill, null);
long fillId = stylesTable.putFill(fill);
assertEquals(2, fillId);
ctFont = CTFont.Factory.newInstance();
XSSFFont font = new XSSFFont(ctFont);
long fontId = stylesTable.putFont(font);
assertEquals(1, fontId);
cellStyleXf = ctStylesheet.addNewCellStyleXfs().addNewXf();
cellStyleXf.setBorderId(1);
cellStyleXf.setFillId(1);
cellStyleXf.setFontId(1);
cellXfs = ctStylesheet.addNewCellXfs();
cellXf = cellXfs.addNewXf();
cellXf.setXfId(1);
cellXf.setBorderId(1);
cellXf.setFillId(1);
cellXf.setFontId(1);
stylesTable.putCellStyleXf(cellStyleXf);
stylesTable.putCellXf(cellXf);
cellStyle = new XSSFCellStyle(1, 1, stylesTable, null);
assertNotNull(stylesTable.getFillAt(1).getCTFill().getPatternFill());
assertEquals(STPatternType.INT_DARK_GRAY, stylesTable.getFillAt(1).getCTFill().getPatternFill().getPatternType().intValue());
}
use of org.apache.poi.xssf.usermodel.extensions.XSSFCellFill in project poi by apache.
the class TestXSSFBugs method bug48779.
/**
* Foreground colours should be found even if
* a theme is used
*/
@Test
public void bug48779() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("48779.xlsx");
XSSFCell cell = wb.getSheetAt(0).getRow(0).getCell(0);
XSSFCellStyle cs = cell.getCellStyle();
assertNotNull(cs);
assertEquals(1, cs.getIndex());
// Look at the low level xml elements
assertEquals(2, cs.getCoreXf().getFillId());
assertEquals(0, cs.getCoreXf().getXfId());
assertEquals(true, cs.getCoreXf().getApplyFill());
XSSFCellFill fg = wb.getStylesSource().getFillAt(2);
assertNotNull(fg.getFillForegroundColor());
assertEquals(0, fg.getFillForegroundColor().getIndexed());
assertEquals(0.0, fg.getFillForegroundColor().getTint(), 0);
assertEquals("FFFF0000", fg.getFillForegroundColor().getARGBHex());
assertNotNull(fg.getFillBackgroundColor());
assertEquals(64, fg.getFillBackgroundColor().getIndexed());
// Now look higher up
assertNotNull(cs.getFillForegroundXSSFColor());
assertEquals(0, cs.getFillForegroundColor());
assertEquals("FFFF0000", cs.getFillForegroundXSSFColor().getARGBHex());
assertEquals("FFFF0000", cs.getFillForegroundColorColor().getARGBHex());
assertNotNull(cs.getFillBackgroundColor());
assertEquals(64, cs.getFillBackgroundColor());
assertEquals(null, cs.getFillBackgroundXSSFColor().getARGBHex());
assertEquals(null, cs.getFillBackgroundColorColor().getARGBHex());
wb.close();
}
use of org.apache.poi.xssf.usermodel.extensions.XSSFCellFill in project poi by apache.
the class XSSFCellStyle method getFillBackgroundXSSFColor.
/**
* Get the background fill color.
* <p>
* Note - many cells are actually filled with a foreground
* fill, not a background fill - see {@link #getFillForegroundColor()}
* </p>
* @see org.apache.poi.xssf.usermodel.XSSFColor#getRGB()
* @return XSSFColor - fill color or <code>null</code> if not set
*/
public XSSFColor getFillBackgroundXSSFColor() {
// bug 56295: handle missing applyFill attribute as "true" because Excel does as well
if (_cellXf.isSetApplyFill() && !_cellXf.getApplyFill())
return null;
int fillIndex = (int) _cellXf.getFillId();
XSSFCellFill fg = _stylesSource.getFillAt(fillIndex);
XSSFColor fillBackgroundColor = fg.getFillBackgroundColor();
if (fillBackgroundColor != null && _theme != null) {
_theme.inheritFromThemeAsRequired(fillBackgroundColor);
}
return fillBackgroundColor;
}
use of org.apache.poi.xssf.usermodel.extensions.XSSFCellFill in project poi by apache.
the class XSSFCellStyle method addFill.
private void addFill(CTFill fill) {
int idx = _stylesSource.putFill(new XSSFCellFill(fill, _stylesSource.getIndexedColors()));
_cellXf.setFillId(idx);
_cellXf.setApplyFill(true);
}
use of org.apache.poi.xssf.usermodel.extensions.XSSFCellFill in project poi by apache.
the class XSSFCellStyle method getFillPatternEnum.
/**
* Get the fill pattern
*
* @return the fill pattern, default value is {@link FillPatternType#NO_FILL}
*/
@Override
public FillPatternType getFillPatternEnum() {
// bug 56295: handle missing applyFill attribute as "true" because Excel does as well
if (_cellXf.isSetApplyFill() && !_cellXf.getApplyFill())
return FillPatternType.NO_FILL;
int fillIndex = (int) _cellXf.getFillId();
XSSFCellFill fill = _stylesSource.getFillAt(fillIndex);
STPatternType.Enum ptrn = fill.getPatternType();
if (ptrn == null)
return FillPatternType.NO_FILL;
return FillPatternType.forInt(ptrn.intValue() - 1);
}
Aggregations