/// <summary> /// Set style of the cell for export. /// Assume the cell belongs to current column. /// </summary> /// <param name="cell">The cell to be set.</param> /// <param name="value">The cell value object.</param> /// <param name="isHeader">If <c>true</c>, use HeaderFormat; otherwise use DataFormat.</param> /// <param name="defaultFormats">The default formats dictionary.</param> /// <param name="helper">The helper object.</param> public void SetCellStyle(ICell cell, object value, bool isHeader, Dictionary <Type, string> defaultFormats, MapHelper helper) { if (cell == null) { throw new ArgumentNullException(nameof(cell)); } if (isHeader && !_headerStyleCached) { _headerStyle = helper.GetCellStyle(cell, null, HeaderFormat); if (_headerStyle == null && HeaderValue != null) { _headerStyle = helper.GetDefaultStyle(cell.Sheet.Workbook, HeaderValue, defaultFormats); } _headerStyleCached = true; } else if (!isHeader && !_dataStyleCached) { _dataStyle = helper.GetCellStyle(cell, Attribute.CustomFormat, DataFormat); if (_dataStyle == null && value != null) { _dataStyle = helper.GetDefaultStyle(cell.Sheet.Workbook, value, defaultFormats); } _dataStyleCached = true; } cell.CellStyle = isHeader ? _headerStyle : _dataStyle; }
/// <summary> /// Set style for the cell. /// </summary> /// <param name="cell">The cell to be set.</param> /// <param name="isHeader">If <c>true</c>, use HeaderFormat; otherwise use DataFormat.</param> public void SetCellStyle(ICell cell, bool isHeader = false) { if (cell != null) { cell.CellStyle = MapHelper.GetCellStyle( cell, isHeader ? null : Attribute.CustomFormat, isHeader ? HeaderFormat ?? 0 : Attribute.BuiltinFormat, isHeader ? HeaderFormat : DataFormat); } }