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