protected virtual void FormatCell(ExcelRange worksheetCell, ExcelReportCell cell) { if (cell.HorizontalAlignment != null) { worksheetCell.Style.HorizontalAlignment = this.GetAlignment(cell.HorizontalAlignment.Value); } if (!string.IsNullOrEmpty(cell.NumberFormat)) { worksheetCell.Style.Numberformat.Format = cell.NumberFormat; } if (cell.IsBold) { worksheetCell.Style.Font.Bold = true; } if (cell.FontColor != null) { worksheetCell.Style.Font.Color.SetColor(cell.FontColor.Value); } if (cell.BackgroundColor != null) { worksheetCell.Style.Fill.PatternType = ExcelFillStyle.Solid; worksheetCell.Style.Fill.BackgroundColor.SetColor(cell.BackgroundColor.Value); } foreach (IEpplusFormatter formatter in this.formatters) { formatter.Format(worksheetCell, cell); } }
public void CellHasDataReturnFalseWhenTheCellValueIsSetToNull() { var cell = new ExcelReportCell(); cell.Value = null; Assert.IsFalse(cell.HasData); }
protected virtual void WriteCell(ExcelRange worksheetCell, ExcelReportCell cell) { worksheetCell.Value = cell.Value; if (cell.ColumnSpan > 1 || cell.RowSpan > 1) { int startRow = worksheetCell.Start.Row; int startColumn = worksheetCell.Start.Column; ExcelRange excelRange = worksheetCell.Worksheet .Cells[startRow, startColumn, startRow + cell.RowSpan - 1, startColumn + cell.ColumnSpan - 1]; excelRange.Merge = true; if (cell.RowSpan > 1) { excelRange.Style.VerticalAlignment = ExcelVerticalAlignment.Center; } } if (cell.HasProperty <SameColumnFormatProperty>()) { int column = worksheetCell.Start.Column; if (!this.columnFormatCells.ContainsKey(column)) { this.columnFormatCells.Add(column, cell); } return; } this.FormatCell(worksheetCell, cell); }
private void AssertHeaderCellStyle(ExcelReportCell cell, ExcelHorizontalAlignment secondColumnAlignmnet, int rowIndex, int cellIndex) { var expectedAlignment = cellIndex == 0 ? ExcelHorizontalAlignment.Left : secondColumnAlignmnet; var expectedStyleName = rowIndex == 0 ? GamePlanReportStyles.HeaderStyle.Name : GamePlanReportStyles.LightHeaderStyle.Name; Assert.AreEqual(expectedAlignment, cell.Alignment); Assert.AreEqual(expectedStyleName, cell.StyleName); Assert.AreEqual(false, cell.AlternateBackground); }
private void AssertBodyCellStyle(ExcelReportCell cell, string firstColumnStyleName, string otherColumnStyleName, ExcelHorizontalAlignment secondColumnAlignmnet, int rowIndex, int cellIndex, bool alternateColor) { var expectedAlignment = cellIndex == 0 ? ExcelHorizontalAlignment.Left : secondColumnAlignmnet; var styleName = cellIndex == 0 ? firstColumnStyleName : otherColumnStyleName; var expectedAlternateColor = alternateColor ? rowIndex % 2 == 1 : false; Assert.AreEqual(expectedAlignment, cell.Alignment); Assert.AreEqual(styleName, cell.StyleName); Assert.AreEqual(expectedAlternateColor, cell.AlternateBackground); }
public void Format(ExcelRange worksheetCell, ExcelReportCell cell) { TProperty property = cell.GetProperty <TProperty>(); if (property == null) { return; } this.Format(worksheetCell, cell, property); }
private void writeCell(IBlockBuilder bb, ExcelReportCell cell, int colSpan) { var b = bb.Add(cell.Value) .HAlign(cell.Alignment) .Style(string.IsNullOrEmpty(cell.StyleName) ? GamePlanReportStyles.DataCellStyle.Name : cell.StyleName) .ColSpan(colSpan); if (cell.AlternateBackground) { b.Background(Color.FromArgb(0xF5, 0xF5, 0xF5)); } }
protected override void Format(ExcelRange worksheetCell, ExcelReportCell cell, ThreeColorHeatmapProperty property) { IExcelConditionalFormattingThreeColorScale threeColorScale = worksheetCell.ConditionalFormatting.AddThreeColorScale(); threeColorScale.LowValue.Type = eExcelConditionalFormattingValueObjectType.Num; threeColorScale.LowValue.Value = (double)property.MinimumValue; threeColorScale.LowValue.Color = property.MinimumColor; threeColorScale.MiddleValue.Type = eExcelConditionalFormattingValueObjectType.Num; threeColorScale.MiddleValue.Value = (double)property.MiddleValue; threeColorScale.MiddleValue.Color = property.MiddleColor; threeColorScale.HighValue.Type = eExcelConditionalFormattingValueObjectType.Num; threeColorScale.HighValue.Value = (double)property.MaximumValue; threeColorScale.HighValue.Color = property.MaximumColor; }
private void WriteNoDataRow(ISheetBuilder sb, int maxColumnCount) { var cell = new ExcelReportCell { Value = "No data", Alignment = ExcelHorizontalAlignment.Center, StyleName = GamePlanReportStyles.EmptyCellStyle.Name }; sb.Block(bb => { writeCell(bb, cell, maxColumnCount); }); }
protected virtual void WriteHeaderCell(ExcelRange worksheetCell, ExcelReportCell cell) { this.WriteCell(worksheetCell, cell); }
protected override void Format(ExcelRange worksheetCell, ExcelReportCell cell, IndentationProperty property) { worksheetCell.Style.HorizontalAlignment = ExcelHorizontalAlignment.Left; worksheetCell.Style.Indent = property.IndentLevel; }
public void CellHasDataReturnTrueWhenTheCellValueHasValue() { var cell = new ExcelReportCell(); Assert.IsFalse(cell.AlternateBackground); }
protected abstract void Format(ExcelRange worksheetCell, ExcelReportCell cell, TProperty property);