Example #1
0
 internal IFont CreateFont(RowStyle rowStyle)
 {
     IColor color = CreateColor(rowStyle.FontColor);
     switch (ExcelVersion){
         case ExcelVersion.XLS:
             var fontExcelXls = new XLSStrategyStyle(ExcelXls);
             return fontExcelXls.GetFont(rowStyle.FontSize, rowStyle.FontName, color);
         case ExcelVersion.XLSX:
             var fontExcelXlsx = new XLSXStrategyStyle(ExcelXlsx);
             return fontExcelXlsx.GetFont(rowStyle.FontSize, rowStyle.FontName, color);
         default:
             throw new Exception(ErrorMessage.Excel_BadVersion);
     }
 }
Example #2
0
 internal ICellStyle CreateCellStyle(RowStyle rowStyle)
 {
     IColor borderColor = CreateColor(rowStyle.BorderColor);
     IColor backColor = CreateColor(rowStyle.BackColor);
     IFont font = CreateFont(rowStyle);
     switch (ExcelVersion)
     {
         case ExcelVersion.XLS:
             var CellStyleXLS = new XLSStrategyStyle(ExcelXls);
             return CellStyleXLS.GetCellStyle(backColor, borderColor, font);
         case ExcelVersion.XLSX:
             var CellStyleXLSX = new XLSXStrategyStyle(ExcelXlsx);
             return CellStyleXLSX.GetCellStyle(backColor, borderColor, font);
         default:
             throw new Exception(ErrorMessage.Excel_BadVersion);
     }
 }
        public static RowStyle GetHeadersFormat(Type type)
        {
            RowStyle rowStyle;
            var defaultFontName = "Calibry";
            var defaultFontColor = "#FFFFFF";
            short defaultFontSize = 11;
            var defaultBorderColor = "#000000";
            var defaultBackColor = "#888888";
            foreach (var ct in type.GetCustomAttributes(true))
            {
                if (ct != null && ct.GetType() == typeof(ExportableExcelHeaderAttribute))
                {
                    ExportableExcelHeaderAttribute exportableAttribute = (ct as ExportableExcelHeaderAttribute);
                    rowStyle = new RowStyle();

                    if (!StringMethods.IsNullOrWhiteSpace(exportableAttribute.FontName))
                        rowStyle.FontName = exportableAttribute.FontName;
                    else
                        rowStyle.FontName = defaultFontName;
                    if (!StringMethods.IsNullOrWhiteSpace(exportableAttribute.FontColor))
                        rowStyle.FontColor = exportableAttribute.FontColor;
                    else
                        rowStyle.FontColor = defaultFontColor;
                    if ((exportableAttribute.FontSize) > 0)
                        rowStyle.FontSize = exportableAttribute.FontSize;
                    else
                        rowStyle.FontSize = defaultFontSize;
                    if (!StringMethods.IsNullOrWhiteSpace(exportableAttribute.BorderColor))
                        rowStyle.BorderColor = exportableAttribute.BorderColor;
                    else
                        rowStyle.BorderColor = defaultBorderColor;
                    if (!StringMethods.IsNullOrWhiteSpace(exportableAttribute.BackColor))
                        rowStyle.BackColor = exportableAttribute.BackColor;
                    else
                        rowStyle.BackColor = defaultBackColor;
                    return rowStyle;
                }

            }

            return new RowStyle(defaultFontColor, defaultFontName, defaultFontSize, defaultBorderColor, defaultBackColor);
        }