Search in sources :

Example 6 with XSSFCellBorder

use of org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder in project poi by apache.

the class XSSFCellStyle method getBottomBorderXSSFColor.

/**
     * Get the color to use for the bottom border as a {@link XSSFColor}
     *
     * @return the used color or <code>null</code> if not set
     */
public XSSFColor getBottomBorderXSSFColor() {
    if (!_cellXf.getApplyBorder())
        return null;
    int idx = (int) _cellXf.getBorderId();
    XSSFCellBorder border = _stylesSource.getBorderAt(idx);
    return border.getBorderColor(BorderSide.BOTTOM);
}
Also used : XSSFCellBorder(org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder)

Example 7 with XSSFCellBorder

use of org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder in project poi by apache.

the class XSSFCellStyle method getCTBorder.

/**
     * Get a <b>copy</b> of the currently used CTBorder, if none is used, return a new instance.
     */
private CTBorder getCTBorder() {
    CTBorder ct;
    if (_cellXf.getApplyBorder()) {
        int idx = (int) _cellXf.getBorderId();
        XSSFCellBorder cf = _stylesSource.getBorderAt(idx);
        ct = (CTBorder) cf.getCTBorder().copy();
    } else {
        ct = CTBorder.Factory.newInstance();
    }
    return ct;
}
Also used : CTBorder(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder) XSSFCellBorder(org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder)

Example 8 with XSSFCellBorder

use of org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder in project poi by apache.

the class XSSFCellStyle method setBorderRight.

/**
     * Set the type of border to use for the right border of the cell
      *
     * @param border the type of border to use
     * @since POI 3.15
     */
@Override
public void setBorderRight(BorderStyle border) {
    CTBorder ct = getCTBorder();
    CTBorderPr pr = ct.isSetRight() ? ct.getRight() : ct.addNewRight();
    if (border == BorderStyle.NONE)
        ct.unsetRight();
    else
        pr.setStyle(STBorderStyle.Enum.forInt(border.getCode() + 1));
    int idx = _stylesSource.putBorder(new XSSFCellBorder(ct, _theme, _stylesSource.getIndexedColors()));
    _cellXf.setBorderId(idx);
    _cellXf.setApplyBorder(true);
}
Also used : CTBorder(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder) CTBorderPr(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorderPr) XSSFCellBorder(org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder)

Example 9 with XSSFCellBorder

use of org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder in project poi by apache.

the class XSSFCellStyle method addBorder.

private void addBorder(CTBorder border) {
    int idx = _stylesSource.putBorder(new XSSFCellBorder(border, _theme, _stylesSource.getIndexedColors()));
    _cellXf.setBorderId(idx);
    _cellXf.setApplyBorder(true);
}
Also used : XSSFCellBorder(org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder)

Example 10 with XSSFCellBorder

use of org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder 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)

Aggregations

XSSFCellBorder (org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder)18 CTBorder (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder)9 CTBorderPr (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorderPr)8 XSSFCellFill (org.apache.poi.xssf.usermodel.extensions.XSSFCellFill)4 XSSFFont (org.apache.poi.xssf.usermodel.XSSFFont)3 IOException (java.io.IOException)1 StylesTable (org.apache.poi.xssf.model.StylesTable)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