/** * Get the cellAlignment object to use for manage alignment * @return XSSFCellAlignment - cell alignment */ internal XSSFCellAlignment GetCellAlignment() { if (this._cellAlignment == null) { this._cellAlignment = new XSSFCellAlignment(GetCTCellAlignment()); } return this._cellAlignment; }
/** * 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. */ public void CloneStyleFrom(ICellStyle source) { if (source is XSSFCellStyle) { XSSFCellStyle src = (XSSFCellStyle)source; // Is it on our Workbook? if (src._stylesSource == _stylesSource) { // Nice and easy _cellXf = src.GetCoreXf(); _cellStyleXf = src.GetStyleXf(); } else { // Copy the style try { // Remove any children off the current style, to // avoid orphaned nodes if (_cellXf.IsSetAlignment()) _cellXf.UnsetAlignment(); if (_cellXf.IsSetExtLst()) _cellXf.UnsetExtLst(); // Create a new Xf with the same contents _cellXf = src.GetCoreXf().Copy(); // Swap it over _stylesSource.ReplaceCellXfAt(_cellXfId, _cellXf); } catch (XmlException e) { throw new POIXMLException(e); } // Copy the format String fmt = src.GetDataFormatString(); DataFormat=( (new XSSFDataFormat(_stylesSource)).GetFormat(fmt) ); // Copy the font try { CT_Font ctFont = src.GetFont().GetCTFont().Clone(); 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 ArgumentException("Can only clone from one XSSFCellStyle to another, not between HSSFCellStyle and XSSFCellStyle"); } }