Search in sources :

Example 16 with CTBorder

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder in project poi by apache.

the class XSSFCellStyle method setBorderTop.

/**
     * Set the type of border to use for the top border of the cell
     *
     * @param border the type of border to use
     * @since POI 3.15
     */
@Override
public void setBorderTop(BorderStyle border) {
    CTBorder ct = getCTBorder();
    CTBorderPr pr = ct.isSetTop() ? ct.getTop() : ct.addNewTop();
    if (border == BorderStyle.NONE)
        ct.unsetTop();
    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 17 with CTBorder

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder in project poi by apache.

the class XSSFCellStyle method getBorderLeftEnum.

/**
     * Get the type of border to use for the left border of the cell
     * Will be removed when {@link #getBorderLeft()} returns a BorderStyle enum
     *
     * @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE}
     * @since POI 3.15
     */
@Override
public BorderStyle getBorderLeftEnum() {
    if (!_cellXf.getApplyBorder())
        return BorderStyle.NONE;
    int idx = (int) _cellXf.getBorderId();
    CTBorder ct = _stylesSource.getBorderAt(idx).getCTBorder();
    STBorderStyle.Enum ptrn = ct.isSetLeft() ? ct.getLeft().getStyle() : null;
    if (ptrn == null) {
        return BorderStyle.NONE;
    }
    return BorderStyle.valueOf((short) (ptrn.intValue() - 1));
}
Also used : CTBorder(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder) STBorderStyle(org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle)

Example 18 with CTBorder

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder in project poi by apache.

the class XSSFCellStyle method cloneStyleFrom.

/**
     * Clones all the style information from another
     *  XSSFCellStyle, onto this one. This
     *  XSSFCellStyle will then have all the same
     *  properties as the source, but the two may
     *  be edited independently.
     * Any stylings on this XSSFCellStyle will be lost!
     *
     * The source XSSFCellStyle could be from another
     *  XSSFWorkbook if you like. This allows you to
     *  copy styles from one XSSFWorkbook to another.
     */
@Override
public void cloneStyleFrom(CellStyle source) {
    if (source instanceof XSSFCellStyle) {
        XSSFCellStyle src = (XSSFCellStyle) source;
        // Is it on our Workbook?
        if (src._stylesSource == _stylesSource) {
            // Nice and easy
            _cellXf.set(src.getCoreXf());
            _cellStyleXf.set(src.getStyleXf());
        } else {
            // Copy the style
            try {
                //  avoid orphaned nodes
                if (_cellXf.isSetAlignment())
                    _cellXf.unsetAlignment();
                if (_cellXf.isSetExtLst())
                    _cellXf.unsetExtLst();
                // Create a new Xf with the same contents
                _cellXf = CTXf.Factory.parse(src.getCoreXf().toString(), DEFAULT_XML_OPTIONS);
                // bug 56295: ensure that the fills is available and set correctly
                CTFill fill = CTFill.Factory.parse(src.getCTFill().toString(), DEFAULT_XML_OPTIONS);
                addFill(fill);
                // bug 58084: set borders correctly
                CTBorder border = CTBorder.Factory.parse(src.getCTBorder().toString(), DEFAULT_XML_OPTIONS);
                addBorder(border);
                // Swap it over
                _stylesSource.replaceCellXfAt(_cellXfId, _cellXf);
            } catch (XmlException e) {
                throw new POIXMLException(e);
            }
            // Copy the format
            String fmt = src.getDataFormatString();
            setDataFormat((new XSSFDataFormat(_stylesSource)).getFormat(fmt));
            // Copy the font
            try {
                CTFont ctFont = CTFont.Factory.parse(src.getFont().getCTFont().toString(), DEFAULT_XML_OPTIONS);
                XSSFFont font = new XSSFFont(ctFont);
                font.registerTo(_stylesSource);
                setFont(font);
            } catch (XmlException e) {
                throw new POIXMLException(e);
            }
        }
        // Clear out cached details
        _font = null;
        _cellAlignment = null;
    } else {
        throw new IllegalArgumentException("Can only clone from one XSSFCellStyle to another, not between HSSFCellStyle and XSSFCellStyle");
    }
}
Also used : CTFill(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill) CTFont(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont) CTBorder(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder) XmlException(org.apache.xmlbeans.XmlException) POIXMLException(org.apache.poi.POIXMLException)

Example 19 with CTBorder

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder in project poi by apache.

the class XSSFCellStyle method setTopBorderColor.

/**
     * Set the color to use for the top border as a {@link XSSFColor} value
     *
     * @param color the color to use
     */
public void setTopBorderColor(XSSFColor color) {
    CTBorder ct = getCTBorder();
    if (color == null && !ct.isSetTop())
        return;
    CTBorderPr pr = ct.isSetTop() ? ct.getTop() : ct.addNewTop();
    if (color != null)
        pr.setColor(color.getCTColor());
    else
        pr.unsetColor();
    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 20 with CTBorder

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder in project poi by apache.

the class XSSFCellStyle method getBorderBottomEnum.

/**
     * Get the type of border to use for the bottom border of the cell
     * Will be removed when {@link #getBorderBottom()} returns a BorderStyle enum
     *
     * @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE}
     * @since POI 3.15
     */
@Override
public BorderStyle getBorderBottomEnum() {
    if (!_cellXf.getApplyBorder())
        return BorderStyle.NONE;
    int idx = (int) _cellXf.getBorderId();
    CTBorder ct = _stylesSource.getBorderAt(idx).getCTBorder();
    STBorderStyle.Enum ptrn = ct.isSetBottom() ? ct.getBottom().getStyle() : null;
    if (ptrn == null) {
        return BorderStyle.NONE;
    }
    return BorderStyle.valueOf((short) (ptrn.intValue() - 1));
}
Also used : CTBorder(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder) STBorderStyle(org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle)

Aggregations

CTBorder (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder)25 CTBorder (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder)11 Test (org.junit.Test)10 CTTblBorders (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblBorders)10 CTTblPr (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblPr)10 XSSFCellBorder (org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder)9 CTBorderPr (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorderPr)9 STBorderStyle (org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle)4 CTString (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTString)2 POIXMLException (org.apache.poi.POIXMLException)1 XmlException (org.apache.xmlbeans.XmlException)1 CTFill (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill)1 CTFont (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont)1 CTStylesheet (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTStylesheet)1 CTP (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP)1 CTPBdr (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPBdr)1 CTPPr (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr)1