Esempio n. 1
0
        ///// <summary>
        ///// 樣式的值是否改變
        ///// </summary>
        //internal bool StyleValueIsChange
        //{
        //    get { return _styleValueIsChange; }
        //    set{_styleValueIsChange =value;}
        //}

        #endregion

        #region 方法

        internal ICellStyle GetCellStyle(NPOI.HSSF.UserModel.HSSFWorkbook workBook)
        {
            if (workBook == null)
            {
                throw new ArgumentNullException("workBook參數不能為NULL。");
            }

            if (_cellStyle == null || _styleValueIsChange)
            {
                _cellStyle = workBook.CreateCellStyle();
                IFont font = workBook.FindFont((short)_fontBold, _fontColor, (short)(_fontSize * 20), _fontName, _isItalic, _isStrikeout, _fontTypeOffset, (byte)_underline);
                if (font == null)
                {
                    font                    = workBook.CreateFont();
                    font.FontName           = this._fontName;
                    font.Boldweight         = (short)this._fontBold;
                    font.FontHeightInPoints = (short)this._fontSize;
                    font.Underline          = (byte)this.UnderLine;
                    font.IsItalic           = _isItalic;
                    font.Color              = _fontColor;
                    font.IsStrikeout        = _isStrikeout;
                    font.TypeOffset         = _fontTypeOffset;
                }
                _cellStyle.SetFont(font);
                IDataFormat format = workBook.CreateDataFormat();
                _cellStyle.BorderBottom      = this._borderBottom;
                _cellStyle.BorderLeft        = this._borderLeft;
                _cellStyle.BorderRight       = this._borderRight;
                _cellStyle.BorderTop         = this._borderTop;
                _cellStyle.Alignment         = this._alignment;
                _cellStyle.VerticalAlignment = this.VerticalAlignment;
                if (!string.IsNullOrEmpty(_dataFormart))
                {
                    _cellStyle.DataFormat = format.GetFormat(this._dataFormart);
                }
                _cellStyle.WrapText = this._warpText;
                _styleValueIsChange = false;
            }
            return(_cellStyle);
        }