diff --git a/common.props b/common.props index 4f196ff..5dbb658 100644 --- a/common.props +++ b/common.props @@ -1,6 +1,6 @@ - 2.2.0 + 2.2.1 An extensions library for both EPPlus and EPPlus.Core packages to generate and manipulate Excel files easily. $(NoWarn);CS1591 diff --git a/src/EPPlus.Core.Extensions/ExcelPackageExtensions.cs b/src/EPPlus.Core.Extensions/ExcelPackageExtensions.cs index 521d89c..67e239b 100644 --- a/src/EPPlus.Core.Extensions/ExcelPackageExtensions.cs +++ b/src/EPPlus.Core.Extensions/ExcelPackageExtensions.cs @@ -66,7 +66,7 @@ public static DataSet ToDataSet(this ExcelPackage package, bool hasHeaderRow = t } /// - /// Converts given worksheet into list of objects as enumerable + /// Converts given package into list of objects as enumerable /// /// /// @@ -76,7 +76,7 @@ public static DataSet ToDataSet(this ExcelPackage package, bool hasHeaderRow = t public static IEnumerable AsEnumerable(this ExcelPackage package, int worksheetIndex = 1, Action> configurationAction = null) where T : class, new() => package.GetWorksheet(worksheetIndex).AsEnumerable(configurationAction); /// - /// Converts given worksheet into list of objects + /// Converts given package into list of objects /// /// /// diff --git a/src/EPPlus.Core.Extensions/ExcelTemplateGenerator.cs b/src/EPPlus.Core.Extensions/ExcelTemplateGenerator.cs index 798889e..fa46d39 100644 --- a/src/EPPlus.Core.Extensions/ExcelTemplateGenerator.cs +++ b/src/EPPlus.Core.Extensions/ExcelTemplateGenerator.cs @@ -8,6 +8,13 @@ namespace EPPlus.Core.Extensions { public static class ExcelTemplateGenerator { + /// + /// Finds given type name in the assembly, and generates Excel package + /// + /// + /// + /// + /// public static ExcelPackage GenerateExcelPackage(this Assembly executingAssembly, string typeName, Action action = null) { var excelPackage = new ExcelPackage(); @@ -15,6 +22,14 @@ public static ExcelPackage GenerateExcelPackage(this Assembly executingAssembly, return excelPackage; } + /// + /// Finds given type name in the assembly, and generates Excel worksheet + /// + /// + /// + /// + /// + /// public static ExcelWorksheet GenerateWorksheet(this ExcelPackage excelPackage, Assembly executingAssembly, string typeName, Action action = null) { Type type = executingAssembly.GetExcelWorksheetMarkedTypeByName(typeName); diff --git a/src/EPPlus.Core.Extensions/Style/ExcelColumnExtensions.cs b/src/EPPlus.Core.Extensions/Style/ExcelColumnExtensions.cs index f133ea8..ffae213 100644 --- a/src/EPPlus.Core.Extensions/Style/ExcelColumnExtensions.cs +++ b/src/EPPlus.Core.Extensions/Style/ExcelColumnExtensions.cs @@ -20,7 +20,7 @@ public static ExcelColumn SetFont(this ExcelColumn column, Font font) } /// - /// Sets the font color of ExcelColumn from a Color object + /// Sets the font color of ExcelColumn /// /// /// @@ -30,7 +30,7 @@ public static ExcelColumn SetFontColor(this ExcelColumn column, Color fontColor) column.Style.SetFontColor(fontColor); return column; } - + /// /// Sets the background color of ExcelColumn from a Color object /// diff --git a/src/EPPlus.Core.Extensions/Style/ExcelRangeExtensions.cs b/src/EPPlus.Core.Extensions/Style/ExcelRangeExtensions.cs index 151653a..ef20a0d 100644 --- a/src/EPPlus.Core.Extensions/Style/ExcelRangeExtensions.cs +++ b/src/EPPlus.Core.Extensions/Style/ExcelRangeExtensions.cs @@ -87,6 +87,12 @@ public static ExcelRangeBase SetFontName(this ExcelRangeBase range, string newFo return range; } + public static ExcelRangeBase SetFontAsBold(this ExcelRangeBase range) + { + range.Style.SetFontAsBold(); + return range; + } + /// /// Sets the horizontal alignment of given range /// diff --git a/src/EPPlus.Core.Extensions/Style/ExcelStyleExtensions.cs b/src/EPPlus.Core.Extensions/Style/ExcelStyleExtensions.cs index 930517a..dcd9260 100644 --- a/src/EPPlus.Core.Extensions/Style/ExcelStyleExtensions.cs +++ b/src/EPPlus.Core.Extensions/Style/ExcelStyleExtensions.cs @@ -97,6 +97,12 @@ public static ExcelStyle SetFontName(this ExcelStyle thisStyle, string newFontNa return thisStyle; } + public static ExcelStyle SetFontAsBold(this ExcelStyle thisStyle) + { + thisStyle.Font.Bold = true; + return thisStyle; + } + /// /// Sets horizontal alignment of Excel style /// diff --git a/src/EPPlus.Core.Extensions/WorksheetWrapper.cs b/src/EPPlus.Core.Extensions/WorksheetWrapper.cs index 2d0096d..9699a85 100644 --- a/src/EPPlus.Core.Extensions/WorksheetWrapper.cs +++ b/src/EPPlus.Core.Extensions/WorksheetWrapper.cs @@ -36,7 +36,7 @@ internal List> AutoGenerateColumns() List properyInfoAndColumnAttributes = typeof(T).GetExcelTableColumnAttributesWithProperyInfo(); foreach (ExcelTableColumnAttributeAndProperyInfo properyInfoAndColumnAttribute in properyInfoAndColumnAttributes) - { + { columns.Add(new WorksheetColumn { Header = properyInfoAndColumnAttribute.ToString(), @@ -127,12 +127,6 @@ internal void AppendWorksheet() } } - /// - /// Generates a Func from a propertyName - /// - /// - /// - /// private Func GetGetter(string propertyName) { ParameterExpression arg = Expression.Parameter(typeof(TP), "x"); diff --git a/test/EPPlus.Core.Extensions.Tests/ExcelTemplateGenerator_Tests.cs b/test/EPPlus.Core.Extensions.Tests/ExcelTemplateGenerator_Tests.cs index 1ff8e3c..792cd88 100644 --- a/test/EPPlus.Core.Extensions.Tests/ExcelTemplateGenerator_Tests.cs +++ b/test/EPPlus.Core.Extensions.Tests/ExcelTemplateGenerator_Tests.cs @@ -57,7 +57,9 @@ public void Should_generate_an_worksheet_from_given_ExcelExportable_class_name() // Act //----------------------------------------------------------------------------------------------------------- ExcelWorksheet worksheet1 = excelPackage.GenerateWorksheet(executingAssembly, wrongCarsType.Name); - ExcelWorksheet worksheet2 = excelPackage.GenerateWorksheet(executingAssembly, defaultMapType.Key, act => act.SetHorizontalAlignment(ExcelHorizontalAlignment.Right)); + ExcelWorksheet worksheet2 = excelPackage.GenerateWorksheet(executingAssembly, defaultMapType.Key, + act => act.SetHorizontalAlignment(ExcelHorizontalAlignment.Right) + .SetFontAsBold()); //----------------------------------------------------------------------------------------------------------- // Assert @@ -70,6 +72,7 @@ public void Should_generate_an_worksheet_from_given_ExcelExportable_class_name() worksheet2.Name.Should().Be("DefaultMap"); worksheet2.GetColumns(1).Count().Should().BeGreaterThan(0); worksheet2.Cells[1, 1].Style.HorizontalAlignment.Should().Be(ExcelHorizontalAlignment.Right); + worksheet2.Cells[1, 2].Style.Font.Bold.Should().BeTrue(); } } }