public OfficeOpenXml.Style.ExcelStyle CreateStyle(string styleName, OfficeOpenXml.Style.ExcelStyle template) { var style = book.Styles.CreateNamedStyle(styleName, template); var result = style.Style; return(result); }
public SubstationsBalanceExport(ExportInfo info) : base(info) { tableStyle = CreateStyle("style_table"); tableStyle.Border.Left.Style = tableStyle.Border.Top.Style = tableStyle.Border.Right.Style = tableStyle.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; tableStyle.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Center; tableStyle.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; tableStyle.WrapText = true; tableStyle.Font.Bold = true; dottedTableCell = CreateStyle("style_dottedTableCell"); dottedTableCell.Border.Left.Style = dottedTableCell.Border.Right.Style = dottedTableCell.Border.Top.Style = dottedTableCell.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Dotted; dottedTableCell.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; dottedTableCell.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Center; titleStyle = base.CreateStyle("style_title"); titleStyle.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; titleStyle.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Center; titleStyle.Font.Bold = true; titleStyle.Font.Name = "Segoe UI"; titleStyle.Font.Size = 14f; titleStyle.Font.Color.SetColor(System.Drawing.Color.Navy); titleStyle.WrapText = true; }
public void SetCellBackgroundColor(string worksheetName, int row, int col, Color color) { ExcelWorksheet excelWrksht = Worksheet(worksheetName); OfficeOpenXml.Style.ExcelStyle style = excelWrksht.Cells[row, col].Style; style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; style.Fill.BackgroundColor.SetColor(color); }
public void SetCellFontStyle(string worksheetName, int row, int col, bool bold, bool italic) { ExcelWorksheet excelWrksht = Worksheet(worksheetName); OfficeOpenXml.Style.ExcelStyle style = excelWrksht.Cells[row, col].Style; style.Font.Bold = bold; style.Font.Italic = italic; }
public SubstationExport(IBalance balance) { if (_balance == null) { throw new ArgumentNullException("SubstationExport - constructor: argument Balance<ENERGY> is null"); } this._balance = balance; tableStyle = CreateStyle("style_table"); tableStyle.Border.Left.Style = tableStyle.Border.Top.Style = tableStyle.Border.Right.Style = tableStyle.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; tableStyle.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Center; tableStyle.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Right; tableHeaderStyle = CreateStyle("style_table_header"); tableHeaderStyle.Border.Left.Style = tableHeaderStyle.Border.Top.Style = tableHeaderStyle.Border.Right.Style = tableHeaderStyle.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; tableHeaderStyle.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Center; tableHeaderStyle.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; tableHeaderStyle.WrapText = true; tableHeaderStyle.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; tableHeaderStyle.Fill.BackgroundColor.SetColor(System.Drawing.Color.FromArgb(255, 255, 153)); cellDateStyle = CreateStyle("cellDateStyle"); cellDateStyle.Border.Left.Style = cellDateStyle.Border.Top.Style = cellDateStyle.Border.Right.Style = cellDateStyle.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; cellDateStyle.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Center; cellDateStyle.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Right; cellDateStyle.Numberformat.Format = "dd.MM.yyyy"; cellTextStyle = CreateStyle("cellTextStyle"); cellTextStyle.Border.Left.Style = cellTextStyle.Border.Top.Style = cellTextStyle.Border.Right.Style = cellTextStyle.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; cellTextStyle.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Center; cellTextStyle.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Right; cellTextStyle.Numberformat.Format = "@"; cellNumbersStyle = CreateStyle("cellNumbersStyle"); cellNumbersStyle.Border.Left.Style = cellNumbersStyle.Border.Top.Style = cellNumbersStyle.Border.Right.Style = cellNumbersStyle.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; cellNumbersStyle.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Center; cellNumbersStyle.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Right; cellNumbersStyle.Numberformat.Format = @"[$-419]#,#0.0_ ;[Red]\-#,#0.0, "; }
public FiderAnaliz(ExportInfo info) : base(info) { tableStyle = CreateStyle("style_table"); tableStyle.Border.Left.Style = tableStyle.Border.Top.Style = tableStyle.Border.Right.Style = tableStyle.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; tableStyle.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Center; tableStyle.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; tableStyle.WrapText = true; tableStyle.Font.Bold = true; }
public void SetCellValue(string worksheetName, int row, int col, object value) { ExcelWorksheet excelWrksht = Worksheet(worksheetName); excelWrksht.Cells[row, col].Value = value; if (null != value) { double proposedCellSize = value.ToString().Trim().Length * 1.5; if (value is DateTime) { OfficeOpenXml.Style.ExcelStyle style = excelWrksht.Cells[row, col].Style; style.Numberformat.Format = "dd.MM.yyyy"; proposedCellSize = ((DateTime)value).ToString("dd.MM.yyyy").Trim().Length * 1.5; } double cellSize = excelWrksht.Cells[row, col].Worksheet.Column(col).Width; if (cellSize <= proposedCellSize) { excelWrksht.Cells[row, col].Worksheet.Column(col).Width = proposedCellSize; } } }
//Set style to resemble a hyperlink private static void HyperlinkStyle(this OfficeOpenXml.Style.ExcelStyle style) { style.Font.UnderLine = true; style.Font.Color.SetColor(Color.Blue); }