Exemple #1
0
 public static void FormatExcelHeader(ExcelWorksheet ws, int iRow, int iColumn, object value, ExcelAlignment align)
 {
     try
     {
         ws.Cells[iRow, iColumn].Value = value;
         using (ExcelRange col = ws.Cells[iRow, iColumn])
         {
             col.Style.Font.Bold = true;
         }
         FormatExcelAlign(ws, iRow, iColumn, align);
     }
     catch (Exception ex)
     {
     }
 }
Exemple #2
0
        public static void FormatExcelAlign(ExcelWorksheet ws, int iRow, int iColumn, ExcelAlignment align)
        {
            using (ExcelRange col = ws.Cells[iRow, iColumn])
            {
                switch (align)
                {
                case ExcelAlignment.Center:
                    col.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                    break;

                case ExcelAlignment.CenterContinuous:
                    col.Style.HorizontalAlignment = ExcelHorizontalAlignment.CenterContinuous;
                    break;

                case ExcelAlignment.Distributed:
                    col.Style.HorizontalAlignment = ExcelHorizontalAlignment.Distributed;
                    break;

                case ExcelAlignment.Fill:
                    col.Style.HorizontalAlignment = ExcelHorizontalAlignment.Fill;
                    break;

                case ExcelAlignment.General:
                    col.Style.HorizontalAlignment = ExcelHorizontalAlignment.General;
                    break;

                case ExcelAlignment.Justify:
                    col.Style.HorizontalAlignment = ExcelHorizontalAlignment.Justify;
                    break;

                case ExcelAlignment.Left:
                    col.Style.HorizontalAlignment = ExcelHorizontalAlignment.Left;
                    break;

                case ExcelAlignment.Right:
                    col.Style.HorizontalAlignment = ExcelHorizontalAlignment.Right;
                    break;

                default:
                    col.Style.HorizontalAlignment = ExcelHorizontalAlignment.Left;
                    break;
                }
            }
        }
Exemple #3
0
        public static void FormatExcelMerge(ExcelWorksheet ws, string RangeRowColumn, object value, string format, ExcelAlignment align,
                                            System.Drawing.Color bgcolor, System.Drawing.Color color, System.Drawing.Font fontFamily)
        {
            try
            {
                ws.Cells[RangeRowColumn].Merge = true;
                ws.Cells[RangeRowColumn].Value = value;
                using (ExcelRange col = ws.Cells[RangeRowColumn])
                {
                    col.Style.Font.SetFromFont(fontFamily);
                    col.Style.Font.Color.SetColor(color);
                    if (bgcolor != System.Drawing.Color.White)
                    {
                        col.Style.Fill.PatternType = ExcelFillStyle.Solid;
                        col.Style.Fill.BackgroundColor.SetColor(bgcolor);

                        col.Style.Border.Top.Style    = ExcelBorderStyle.Thin;
                        col.Style.Border.Right.Style  = ExcelBorderStyle.Thin;
                        col.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
                        col.Style.Border.Left.Style   = ExcelBorderStyle.Thin;
                        col.Style.Border.Top.Color.SetColor(System.Drawing.Color.Silver);
                        col.Style.Border.Right.Color.SetColor(System.Drawing.Color.Silver);
                        col.Style.Border.Bottom.Color.SetColor(System.Drawing.Color.Silver);
                        col.Style.Border.Left.Color.SetColor(System.Drawing.Color.Silver);
                    }
                    if (!string.IsNullOrEmpty(format))
                    {
                        col.Style.Numberformat.Format = format;
                    }
                    switch (align)
                    {
                    case ExcelAlignment.Center:
                        col.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                        break;

                    case ExcelAlignment.CenterContinuous:
                        col.Style.HorizontalAlignment = ExcelHorizontalAlignment.CenterContinuous;
                        break;

                    case ExcelAlignment.Distributed:
                        col.Style.HorizontalAlignment = ExcelHorizontalAlignment.Distributed;
                        break;

                    case ExcelAlignment.Fill:
                        col.Style.HorizontalAlignment = ExcelHorizontalAlignment.Fill;
                        break;

                    case ExcelAlignment.General:
                        col.Style.HorizontalAlignment = ExcelHorizontalAlignment.General;
                        break;

                    case ExcelAlignment.Justify:
                        col.Style.HorizontalAlignment = ExcelHorizontalAlignment.Justify;
                        break;

                    case ExcelAlignment.Left:
                        col.Style.HorizontalAlignment = ExcelHorizontalAlignment.Left;
                        break;

                    case ExcelAlignment.Right:
                        col.Style.HorizontalAlignment = ExcelHorizontalAlignment.Right;
                        break;

                    default:
                        col.Style.HorizontalAlignment = ExcelHorizontalAlignment.Left;
                        break;
                    }
                }
            }
            catch (Exception ex) { }
        }
Exemple #4
0
 public static void FormatExcelString(ExcelWorksheet ws, int iRow, int iColumn, object value, ExcelAlignment align)
 {
     try
     {
         ws.Cells[iRow, iColumn].Value = value;
         FormatExcelAlign(ws, iRow, iColumn, align);
     }
     catch (Exception ex) { }
 }