use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont 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.spreadsheetml.x2006.main.CTFont in project poi by apache.
the class XSSFRichTextString method setRunAttributes.
/**
* Copy font attributes from CTFont bean into CTRPrElt bean
*/
private void setRunAttributes(CTFont ctFont, CTRPrElt pr) {
if (ctFont.sizeOfBArray() > 0)
pr.addNewB().setVal(ctFont.getBArray(0).getVal());
if (ctFont.sizeOfUArray() > 0)
pr.addNewU().setVal(ctFont.getUArray(0).getVal());
if (ctFont.sizeOfIArray() > 0)
pr.addNewI().setVal(ctFont.getIArray(0).getVal());
if (ctFont.sizeOfColorArray() > 0) {
CTColor c1 = ctFont.getColorArray(0);
CTColor c2 = pr.addNewColor();
if (c1.isSetAuto())
c2.setAuto(c1.getAuto());
if (c1.isSetIndexed())
c2.setIndexed(c1.getIndexed());
if (c1.isSetRgb())
c2.setRgb(c1.getRgb());
if (c1.isSetTheme())
c2.setTheme(c1.getTheme());
if (c1.isSetTint())
c2.setTint(c1.getTint());
}
if (ctFont.sizeOfSzArray() > 0)
pr.addNewSz().setVal(ctFont.getSzArray(0).getVal());
if (ctFont.sizeOfNameArray() > 0)
pr.addNewRFont().setVal(ctFont.getNameArray(0).getVal());
if (ctFont.sizeOfFamilyArray() > 0)
pr.addNewFamily().setVal(ctFont.getFamilyArray(0).getVal());
if (ctFont.sizeOfSchemeArray() > 0)
pr.addNewScheme().setVal(ctFont.getSchemeArray(0).getVal());
if (ctFont.sizeOfCharsetArray() > 0)
pr.addNewCharset().setVal(ctFont.getCharsetArray(0).getVal());
if (ctFont.sizeOfCondenseArray() > 0)
pr.addNewCondense().setVal(ctFont.getCondenseArray(0).getVal());
if (ctFont.sizeOfExtendArray() > 0)
pr.addNewExtend().setVal(ctFont.getExtendArray(0).getVal());
if (ctFont.sizeOfVertAlignArray() > 0)
pr.addNewVertAlign().setVal(ctFont.getVertAlignArray(0).getVal());
if (ctFont.sizeOfOutlineArray() > 0)
pr.addNewOutline().setVal(ctFont.getOutlineArray(0).getVal());
if (ctFont.sizeOfShadowArray() > 0)
pr.addNewShadow().setVal(ctFont.getShadowArray(0).getVal());
if (ctFont.sizeOfStrikeArray() > 0)
pr.addNewStrike().setVal(ctFont.getStrikeArray(0).getVal());
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont in project poi by apache.
the class XSSFRichTextString method toCTFont.
/**
*
* CTRPrElt --> CTFont adapter
*/
protected static CTFont toCTFont(CTRPrElt pr) {
CTFont ctFont = CTFont.Factory.newInstance();
// Bug 58315: there are files where there is no pr-entry for a RichTextString
if (pr == null) {
return ctFont;
}
if (pr.sizeOfBArray() > 0)
ctFont.addNewB().setVal(pr.getBArray(0).getVal());
if (pr.sizeOfUArray() > 0)
ctFont.addNewU().setVal(pr.getUArray(0).getVal());
if (pr.sizeOfIArray() > 0)
ctFont.addNewI().setVal(pr.getIArray(0).getVal());
if (pr.sizeOfColorArray() > 0) {
CTColor c1 = pr.getColorArray(0);
CTColor c2 = ctFont.addNewColor();
if (c1.isSetAuto())
c2.setAuto(c1.getAuto());
if (c1.isSetIndexed())
c2.setIndexed(c1.getIndexed());
if (c1.isSetRgb())
c2.setRgb(c1.getRgb());
if (c1.isSetTheme())
c2.setTheme(c1.getTheme());
if (c1.isSetTint())
c2.setTint(c1.getTint());
}
if (pr.sizeOfSzArray() > 0)
ctFont.addNewSz().setVal(pr.getSzArray(0).getVal());
if (pr.sizeOfRFontArray() > 0)
ctFont.addNewName().setVal(pr.getRFontArray(0).getVal());
if (pr.sizeOfFamilyArray() > 0)
ctFont.addNewFamily().setVal(pr.getFamilyArray(0).getVal());
if (pr.sizeOfSchemeArray() > 0)
ctFont.addNewScheme().setVal(pr.getSchemeArray(0).getVal());
if (pr.sizeOfCharsetArray() > 0)
ctFont.addNewCharset().setVal(pr.getCharsetArray(0).getVal());
if (pr.sizeOfCondenseArray() > 0)
ctFont.addNewCondense().setVal(pr.getCondenseArray(0).getVal());
if (pr.sizeOfExtendArray() > 0)
ctFont.addNewExtend().setVal(pr.getExtendArray(0).getVal());
if (pr.sizeOfVertAlignArray() > 0)
ctFont.addNewVertAlign().setVal(pr.getVertAlignArray(0).getVal());
if (pr.sizeOfOutlineArray() > 0)
ctFont.addNewOutline().setVal(pr.getOutlineArray(0).getVal());
if (pr.sizeOfShadowArray() > 0)
ctFont.addNewShadow().setVal(pr.getShadowArray(0).getVal());
if (pr.sizeOfStrikeArray() > 0)
ctFont.addNewStrike().setVal(pr.getStrikeArray(0).getVal());
return ctFont;
}
Aggregations