Exemplo n.º 1
0
        /// <summary>
        /// convert the StyleAttribute to the CellStyle object
        /// </summary>
        /// <param name="attr">the object of the StyleAttribute</param>
        /// <returns>the CellStyle</returns>
        protected virtual ICellStyle FillCellStyle(StyleAttribute attr)
        {
            if (attr == null)
            {
                return(null);
            }
            ICellStyle style;

            if (WorkbookType == ExcelType.Excel2003)
            {
                style = FillCellStyle2003(attr);
            }
            else
            {
                style = FillCellStyle2007(attr);
            }
            style.Alignment         = attr.TextAlign;
            style.VerticalAlignment = attr.VerticalAlign;
            var font = FillFont(attr);

            if (font != null)
            {
                style.SetFont(font);
            }
            return(style);
        }
Exemplo n.º 2
0
        private XSSFFont FillFont2007(StyleAttribute attr)
        {
            var font = (XSSFFont)((XSSFWorkbook)Workbook).CreateFont();

            if (!string.IsNullOrEmpty(attr.TextColor))
            {
                var color = attr.TextColor.ToColor();
                if (color.HasValue)
                {
                    font.SetColor(GetColor2007(color.Value));
                }
            }
            return(font);
        }
Exemplo n.º 3
0
 /// <summary>
 /// convert StyleAttribute to the excel font
 /// </summary>
 /// <param name="attr">the value of the StyleAttribute</param>
 /// <returns>the font</returns>
 protected virtual IFont FillFont(StyleAttribute attr)
 {
     if (attr == null)
     {
         return(null);
     }
     if (attr.FontWeight > 0 ||
         !string.IsNullOrEmpty(attr.FontFamily) ||
         attr.FontSize > 0 ||
         attr.IsItalic ||
         !string.IsNullOrEmpty(attr.TextColor))
     {
         IFont font;
         if (WorkbookType == ExcelType.Excel2003)
         {
             font = FillFont2003(attr);
         }
         else
         {
             font = FillFont2007(attr);
         }
         if (attr.FontWeight > 0)
         {
             font.Boldweight = attr.FontWeight;
         }
         if (!string.IsNullOrEmpty(attr.FontFamily))
         {
             font.FontName = attr.FontFamily;
         }
         if (attr.FontSize > 0)
         {
             font.FontHeightInPoints = attr.FontSize;
         }
         if (attr.IsItalic)
         {
             font.IsItalic = true;
         }
         return(font);
     }
     return(null);
 }
Exemplo n.º 4
0
        private XSSFCellStyle FillCellStyle2007(StyleAttribute attr)
        {
            var style = (XSSFCellStyle)((XSSFWorkbook)Workbook).CreateCellStyle();

            if (!string.IsNullOrEmpty(attr.BackgroundColor))
            {
                var color = attr.BackgroundColor.ToColor();
                if (color.HasValue)
                {
                    style.SetFillBackgroundColor(GetColor2007(color.Value));
                    style.FillPattern = attr.FillPattern;
                }
            }
            if (!string.IsNullOrEmpty(attr.ForegroundColor))
            {
                var color = attr.ForegroundColor.ToColor();
                if (color.HasValue)
                {
                    style.SetFillForegroundColor(GetColor2007(color.Value));
                    style.FillPattern = attr.FillPattern;
                }
            }
            return(style);
        }