Example #1
0
 private IWorksheetCellFormat ApplyCellFormatFromStyle(Workbook workbook, IWorksheetCellFormat cellFormat, CssStyle cssStyle, WebDataGrid grid)
 {
     if (Color.Empty != cssStyle.Background.Color && cssStyle.Background.Color.ToArgb() != Color.White.ToArgb())
     {
         cellFormat.FillPatternForegroundColor = cssStyle.Background.Color;
         cellFormat.FillPattern = FillPatternStyle.Solid;
     }
     IWorkbookFont newWorkbookFont = workbook.CreateNewWorkbookFont();
     newWorkbookFont.Color = grid.ForeColor.IsEmpty ? cssStyle.Color : grid.ForeColor;
     newWorkbookFont.Name = string.IsNullOrEmpty(grid.Font.Name) ? cssStyle.Font.FamilyName : grid.Font.Name;
     switch (cssStyle.Font.SizeEnum)
     {
         case Infragistics.Documents.Reports.FontSize.NotSet:
             newWorkbookFont.Height = cssStyle.Font.SizeUnit.Type != UnitType.Point || cssStyle.Font.SizeUnit.Value < 1.0 ? (cssStyle.Font.SizeUnit.Type != UnitType.Pixel || cssStyle.Font.SizeUnit.Value < 1.0 ? 240 : (int)(cssStyle.Font.SizeUnit.Value * 20.0)) : (int)(cssStyle.Font.SizeUnit.Value * 20.0);
             break;
         case Infragistics.Documents.Reports.FontSize.Large:
         case Infragistics.Documents.Reports.FontSize.Larger:
             newWorkbookFont.Height = 280;
             break;
         case Infragistics.Documents.Reports.FontSize.Small:
         case Infragistics.Documents.Reports.FontSize.Smaller:
             newWorkbookFont.Height = 200;
             break;
         case Infragistics.Documents.Reports.FontSize.X_Large:
             newWorkbookFont.Height = 360;
             break;
         case Infragistics.Documents.Reports.FontSize.X_Small:
             newWorkbookFont.Height = 180;
             break;
         case Infragistics.Documents.Reports.FontSize.XX_Large:
             newWorkbookFont.Height = 480;
             break;
         case Infragistics.Documents.Reports.FontSize.XX_Small:
             newWorkbookFont.Height = 160;
             break;
         default:
             newWorkbookFont.Height = 240;
             break;
     }
     if (cssStyle.Font.IsBold || cssStyle.Font.Style == Infragistics.Documents.Reports.FontStyle.Oblique || grid.Font.Bold)
         newWorkbookFont.Bold = ExcelDefaultableBoolean.True;
     if (cssStyle.Font.IsItalic || cssStyle.Font.Style == Infragistics.Documents.Reports.FontStyle.Italic || grid.Font.Italic)
         newWorkbookFont.Italic = ExcelDefaultableBoolean.True;
     if (cssStyle.TextDecoration == TextDecoration.Line_Through || grid.Font.Strikeout)
         newWorkbookFont.Strikeout = ExcelDefaultableBoolean.True;
     if (cssStyle.TextDecoration == TextDecoration.Underline || grid.Font.Underline)
         newWorkbookFont.UnderlineStyle = FontUnderlineStyle.Single;
     cellFormat.Font.SetFontFormatting(newWorkbookFont);
     switch (cssStyle.TextAlign)
     {
         case Infragistics.Documents.Reports.TextAlign.Center:
             cellFormat.Alignment = HorizontalCellAlignment.Center;
             break;
         case Infragistics.Documents.Reports.TextAlign.Justify:
             cellFormat.Alignment = HorizontalCellAlignment.Justify;
             break;
         case Infragistics.Documents.Reports.TextAlign.Left:
             cellFormat.Alignment = HorizontalCellAlignment.Left;
             break;
         case Infragistics.Documents.Reports.TextAlign.Right:
             cellFormat.Alignment = HorizontalCellAlignment.Right;
             break;
         default:
             cellFormat.Alignment = HorizontalCellAlignment.General;
             break;
     }
     switch (cssStyle.VerticalAlign)
     {
         case Infragistics.Documents.Reports.VerticalAlign.Bottom:
             cellFormat.VerticalAlignment = VerticalCellAlignment.Bottom;
             break;
         case Infragistics.Documents.Reports.VerticalAlign.Middle:
             cellFormat.VerticalAlignment = VerticalCellAlignment.Center;
             break;
         case Infragistics.Documents.Reports.VerticalAlign.Top:
             cellFormat.VerticalAlignment = VerticalCellAlignment.Top;
             break;
         default:
             cellFormat.VerticalAlignment = VerticalCellAlignment.Default;
             break;
     }
     return cellFormat;
 }