Search in sources :

Example 6 with XSSFCellFill

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());
}
Also used : StylesTable(org.apache.poi.xssf.model.StylesTable) XSSFCellFill(org.apache.poi.xssf.usermodel.extensions.XSSFCellFill) XSSFCellBorder(org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder) Before(org.junit.Before)

Example 7 with XSSFCellFill

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();
}
Also used : SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) XSSFCellFill(org.apache.poi.xssf.usermodel.extensions.XSSFCellFill) Test(org.junit.Test)

Example 8 with XSSFCellFill

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;
}
Also used : XSSFCellFill(org.apache.poi.xssf.usermodel.extensions.XSSFCellFill)

Example 9 with XSSFCellFill

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);
}
Also used : XSSFCellFill(org.apache.poi.xssf.usermodel.extensions.XSSFCellFill)

Example 10 with XSSFCellFill

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);
}
Also used : STPatternType(org.openxmlformats.schemas.spreadsheetml.x2006.main.STPatternType) XSSFCellFill(org.apache.poi.xssf.usermodel.extensions.XSSFCellFill)

Aggregations

XSSFCellFill (org.apache.poi.xssf.usermodel.extensions.XSSFCellFill)10 XSSFCellBorder (org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder)4 XSSFFont (org.apache.poi.xssf.usermodel.XSSFFont)3 IOException (java.io.IOException)1 StylesTable (org.apache.poi.xssf.model.StylesTable)1 SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)1 CustomIndexedColorMap (org.apache.poi.xssf.usermodel.CustomIndexedColorMap)1 DefaultIndexedColorMap (org.apache.poi.xssf.usermodel.DefaultIndexedColorMap)1 IndexedColorMap (org.apache.poi.xssf.usermodel.IndexedColorMap)1 XSSFTableStyle (org.apache.poi.xssf.usermodel.XSSFTableStyle)1 XmlException (org.apache.xmlbeans.XmlException)1 Before (org.junit.Before)1 Test (org.junit.Test)1 CTFill (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill)1 STPatternType (org.openxmlformats.schemas.spreadsheetml.x2006.main.STPatternType)1