Exemple #1
0
 private void AddWorksheetTitle(ExcelWorksheet worksheet, int startRow, int endColumn)
 {
     Models.MergeInfo merge = new Models.MergeInfo(2, "A", 2, 25.ToColumnLetter());
     AddMerge(worksheet, merge);
     worksheet.Cells[startRow, 1].Value = _ExcelOptions.WorksheetTitle;
     //worksheet.Cells[merge.RangeName].Style.Font.Bold = true;
     worksheet.Cells[startRow, 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.Right;
     worksheet.Cells[startRow, 1].Style.Font.SetFromFont(_ExcelOptions.TitleFont);
     worksheet.Cells[startRow, 1].Style.ReadingOrder = ExcelReadingOrder.ContextDependent;
 }
Exemple #2
0
        private void AddColumns(ExcelWorksheet worksheet, int startRow)
        {
            //
            var columns = _ExcelOptions.ColumnList.ToList();

            for (int i = 1; i <= columns.Count(); i++)
            {
                worksheet.Cells[startRow, i].Value = columns[i - 1].ColumnName;
                worksheet.Column(i).Width          = columns[i - 1].ColumnWidth;
            }
            //
            //border around headers
            //if (_ExcelOptions.BorderAroundColumnHeaders || _ExcelOptions.SetColumnHeadersBackgroundColor)
            Models.MergeInfo mergeBorder = new Models.MergeInfo(startRow, "A", startRow, columns.Count().ToColumnLetter());
            using (ExcelRange r = worksheet.Cells[mergeBorder.RangeName])
            {
                r.AutoFilter = true;
                if (_ExcelOptions.SetColumnHeadersBackgroundColor)
                {
                    r.Style.Border.Top.Style    = ExcelBorderStyle.Medium;
                    r.Style.Border.Right.Style  = ExcelBorderStyle.Medium;
                    r.Style.Border.Bottom.Style = ExcelBorderStyle.Medium;
                    r.Style.Border.Left.Style   = ExcelBorderStyle.Medium;
                }
                //.Selection.Interior.ColorIndex = 47
                //.Selection.Font.ColorIndex = 2
                if (_ExcelOptions.SetColumnHeadersBackgroundColor)
                {
                    r.Style.Fill.PatternType = ExcelFillStyle.Solid;
                    //r.Style.Fill.BackgroundColor.SetColor(System.Drawing.ColorTranslator.FromHtml("#666699"));
                    r.Style.Fill.BackgroundColor.SetColor(_ExcelOptions.ColumnHeadersBackgroundColor);

                    //r.Style.Font.Color.SetColor(System.Drawing.ColorTranslator.FromHtml("#FFFFFF"));
                    r.Style.Font.Color.SetColor(_ExcelOptions.ColumnHeadersTextColor);
                }
            }
        }