Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ClosedXML.Report/Excel/SubtotalGroup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using ClosedXML.Excel;

namespace ClosedXML.Report.Excel
Expand Down
1 change: 0 additions & 1 deletion ClosedXML.Report/Excel/SubtotalSummaryFunc.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq.Expressions;
using ClosedXML.Report.Utils;

namespace ClosedXML.Report.Excel
Expand Down
1 change: 0 additions & 1 deletion ClosedXML.Report/FormulaEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Linq.Dynamic.Core.Exceptions;
using System.Linq.Expressions;
using System.Reflection;
using System.Text.RegularExpressions;
Expand Down
4 changes: 1 addition & 3 deletions ClosedXML.Report/Options/AutoFilterTag.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using ClosedXML.Report.Excel;

namespace ClosedXML.Report.Options
namespace ClosedXML.Report.Options
{
public class AutoFilterTag : OptionTag
{
Expand Down
3 changes: 1 addition & 2 deletions ClosedXML.Report/Options/HiddenTag.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using ClosedXML.Excel;
using MoreLinq;
using MoreLinq;

namespace ClosedXML.Report.Options
{
Expand Down
3 changes: 2 additions & 1 deletion ClosedXML.Report/Options/ImageTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public override void Execute(ProcessingContext context)
case Stream stream: picture = xlCell.Worksheet.AddPicture(stream); break;
case string path: picture = xlCell.Worksheet.AddPicture(path); break;
default: throw new TemplateParseException("Unsupported image type.", xlCell.AsRange());
};
}

picture.MoveTo(xlCell);
if (!string.IsNullOrEmpty(ImageName)) picture.Name = ImageName;
if (Scale > 0) picture.Scale(Scale);
Expand Down
1 change: 0 additions & 1 deletion ClosedXML.Report/Options/OptionTag.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using ClosedXML.Excel;
using ClosedXML.Report.Excel;

namespace ClosedXML.Report.Options
{
Expand Down
4 changes: 0 additions & 4 deletions ClosedXML.Report/Options/ValidationTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ InputMessage String
================================================
*/

using ClosedXML.Excel;
using ClosedXML.Report.Excel;
using ClosedXML.Report.Utils;

namespace ClosedXML.Report.Options
{
public class ValidationTag: OptionTag
Expand Down
2 changes: 1 addition & 1 deletion ClosedXML.Report/TemplateParseException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public TemplateParseException(string message, IXLRange range) : base(message)
Range = range;
}

public TemplateParseException(string message, TemplateErrors errors)
public TemplateParseException(string message, TemplateErrors errors) : base(message)
{
InnerErrors = errors;
}
Expand Down
4 changes: 2 additions & 2 deletions ClosedXML.Report/Utils/EnumExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ private static ulong ToUInt64(object value)
case TypeCode.Int16:
case TypeCode.Int32:
case TypeCode.Int64:
return (ulong)Convert.ToInt64(value, (IFormatProvider)CultureInfo.InvariantCulture);
return (ulong)Convert.ToInt64(value, CultureInfo.InvariantCulture);
case TypeCode.Byte:
case TypeCode.UInt16:
case TypeCode.UInt32:
case TypeCode.UInt64:
return Convert.ToUInt64(value, (IFormatProvider)CultureInfo.InvariantCulture);
return Convert.ToUInt64(value, CultureInfo.InvariantCulture);
default:
throw new InvalidOperationException("Invalid operation: Unknown enum type");
}
Expand Down
16 changes: 5 additions & 11 deletions ClosedXML.Report/Utils/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static Type ToType(this TypeCode code)
return typeof(double);

case TypeCode.Empty:
return null;
break;

case TypeCode.Int16:
return typeof(short);
Expand Down Expand Up @@ -180,22 +180,16 @@ public static PropertyInfo GetPropertyInfo<TSource, TProperty>(
Expression<Func<TSource, TProperty>> propertyLambda)
{
if (!(propertyLambda.Body is MemberExpression member))
throw new ArgumentException(string.Format(
"Expression '{0}' refers to a method, not a property.",
propertyLambda.ToString()));
throw new ArgumentException($"Expression '{propertyLambda}' refers to a method, not a property.");

PropertyInfo propInfo = member.Member as PropertyInfo;
if (propInfo == null)
throw new ArgumentException(string.Format(
"Expression '{0}' refers to a field, not a property.",
propertyLambda.ToString()));
throw new ArgumentException($"Expression '{propertyLambda}' refers to a field, not a property.");

if (type != propInfo.ReflectedType &&
!type.IsSubclassOf(propInfo.ReflectedType))
throw new ArgumentException(string.Format(
"Expresion '{0}' refers to a property that is not from type {1}.",
propertyLambda.ToString(),
type));
throw new ArgumentException(
$"Expression '{propertyLambda}' refers to a property that is not from type {type}.");

return propInfo;
}
Expand Down
1 change: 0 additions & 1 deletion ClosedXML.Report/Utils/XLDynamicExpressionParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Linq.Dynamic.Core;
using System.Linq.Dynamic.Core.CustomTypeProviders;
using System.Linq.Expressions;
using System.Text;

namespace ClosedXML.Report.Utils
{
Expand Down
3 changes: 1 addition & 2 deletions tests/ClosedXML.Report.Tests/AutoFilterTagTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using ClosedXML.Excel;
using ClosedXML.Report.Options;
using ClosedXML.Report.Options;
using FluentAssertions;
using Xunit;

Expand Down
2 changes: 1 addition & 1 deletion tests/ClosedXML.Report.Tests/FormulaEvaluatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void EvalExpressionVariableWithAt()
[Fact]
public void ExpressionParseTestNullPropagation()
{
var customers = new Customer[]
var customers = new[]
{
new Customer {Id = 1, Name = "Customer1", Manager = new Customer { Id = 3, Name = "Manager1"}},
new Customer {Id = 2, Name = "Customer2", Manager = null}
Expand Down
10 changes: 5 additions & 5 deletions tests/ClosedXML.Report.Tests/ReportOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ReportOptionsTests : XlsxTemplateTestsBase
public void Hidden_option_should_hide_sheet()
{
XlTemplateTest("5_options.xlsx",
tpl => { },
_ => { },
wb =>
{
wb.Worksheets.Count.Should().Be(3);
Expand All @@ -28,7 +28,7 @@ public void Hidden_option_should_hide_sheet()
public void OnlyValues_option_should_remove_formulas_on_sheet()
{
XlTemplateTest("5_options.xlsx",
tpl => { },
_ => { },
wb =>
{
var worksheet = wb.Worksheet(1);
Expand All @@ -44,7 +44,7 @@ public void OnlyValues_option_should_remove_formulas_on_sheet()
public void ColsFit_option_should_FitWidth()
{
XlTemplateTest("5_options.xlsx",
tpl => { },
_ => { },
wb =>
{
var worksheet = wb.Worksheet(1);
Expand Down Expand Up @@ -80,8 +80,8 @@ public void DeleteOptionsWithParameter()
{
using (var db = new DbDemos())
{
var cust = db.customers.LoadWith(x => x.Orders.First().Items).OrderBy(c => c.CustNo).First(x => x.CustNo == 1356);
tpl.AddVariable(cust);
var customer = db.customers.LoadWith(x => x.Orders.First().Items).OrderBy(c => c.CustNo).First(x => x.CustNo == 1356);
tpl.AddVariable(customer);
}
tpl.AddVariable("disableCColumnDeletion", "true");
tpl.AddVariable("disableEColumnDeletion", "false");
Expand Down
4 changes: 2 additions & 2 deletions tests/ClosedXML.Report.Tests/SubrangesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private IEnumerable<dynamic> GenerateVisitors()
{
return new List<dynamic>
{
new { Name = "Alice", Attendance = new List<dynamic> { } },
new { Name = "Alice", Attendance = new List<dynamic>() },
new { Name = "Bob", Attendance = new List<dynamic> {
new { Month = "February", Visits = 2 },
new { Month = "March", Visits = 3 },
Expand All @@ -143,7 +143,7 @@ private IEnumerable<dynamic> GenerateVisitors()
new { Month = "July", Visits = 8 },
new { Month = "October", Visits = 6 },
} },
new { Name = "Daniel", Attendance = new List<dynamic> { } },
new { Name = "Daniel", Attendance = new List<dynamic>() },
};
}

Expand Down
78 changes: 42 additions & 36 deletions tests/ClosedXML.Report.Tests/SubtotalSummaryFuncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,25 @@ namespace ClosedXML.Report.Tests
{
public class SubtotalSummaryFuncTests : XlsxTemplateTestsBase
{
private IXLRange _rng;
private XLWorkbook _workbook;

public SubtotalSummaryFuncTests(ITestOutputHelper output) : base(output)
{
var fileName = Path.Combine(TestConstants.TemplatesFolder, "9_plaindata.xlsx");
_workbook = new XLWorkbook(fileName);
_rng = _workbook.Range("range1");
_rng.InsertColumnsAfter(1, true);
var clmn = _rng.LastColumn().ColumnNumber() - _rng.FirstColumn().ColumnNumber() + 1;
for (int i = 1; i <= _rng.RowCount(); i++)
var workbook = new XLWorkbook(fileName);
var rng = workbook.Range("range1");
rng.InsertColumnsAfter(1, true);
var clmn = rng.LastColumn().ColumnNumber() - rng.FirstColumn().ColumnNumber() + 1;
for (int i = 1; i <= rng.RowCount(); i++)
{
_rng.Row(i).Cell(clmn).Value = i - 1;
rng.Row(i).Cell(clmn).Value = i - 1;
}
}

[Fact]
public void SumIntTest()
{
var sum = new SubtotalSummaryFunc("sum", 1);
Expression<Func<Test, object>> e = o => o.val;
sum.GetCalculateDelegate = type => e.Compile();
Expression<Func<Test, object>> e = o => o.Val;
sum.GetCalculateDelegate = _ => e.Compile();
sum.DataSource = new DataSource(new object[] { new Test(1), new Test(2), new Test(3) });

sum.Calculate(sum.DataSource).Should().Be(6);
Expand All @@ -42,8 +39,8 @@ public void SumIntTest()
public void SumDoubleTest()
{
var sum = new SubtotalSummaryFunc("sum", 1);
Expression<Func<Test, object>> e = o => o.val;
sum.GetCalculateDelegate = type => e.Compile();
Expression<Func<Test, object>> e = o => o.Val;
sum.GetCalculateDelegate = _ => e.Compile();
sum.DataSource = new DataSource(new object[] { new Test(1.5), new Test(2d), new Test(3.5) });

sum.Calculate(sum.DataSource).Should().Be(7d);
Expand All @@ -53,9 +50,10 @@ public void SumDoubleTest()
public void SumTimeSpanTest()
{
var sum = new SubtotalSummaryFunc("sum", 1);
Expression<Func<Test, object>> e = o => o.val;
sum.GetCalculateDelegate = type => (e.Compile());
sum.DataSource = new DataSource(new object[] { new Test(TimeSpan.FromHours(1)), new Test(TimeSpan.FromHours(2)), new Test(TimeSpan.FromHours(3)) });
Expression<Func<Test, object>> e = o => o.Val;
sum.GetCalculateDelegate = _ => (e.Compile());
sum.DataSource = new DataSource(new object[]
{ new Test(TimeSpan.FromHours(1)), new Test(TimeSpan.FromHours(2)), new Test(TimeSpan.FromHours(3)) });

sum.Calculate(sum.DataSource).Should().Be(TimeSpan.FromHours(6));
}
Expand All @@ -64,8 +62,8 @@ public void SumTimeSpanTest()
public void AverageIntTest()
{
var sum = new SubtotalSummaryFunc("average", 1);
Expression<Func<Test, object>> e = o => o.val;
sum.GetCalculateDelegate = type => (e.Compile());
Expression<Func<Test, object>> e = o => o.Val;
sum.GetCalculateDelegate = _ => (e.Compile());
sum.DataSource = new DataSource(new object[] { new Test(1), new Test(2), new Test(3) });

sum.Calculate(sum.DataSource).Should().Be(2);
Expand All @@ -75,8 +73,8 @@ public void AverageIntTest()
public void AverageDoubleTest()
{
var sum = new SubtotalSummaryFunc("average", 1);
Expression<Func<Test, object>> e = o => o.val;
sum.GetCalculateDelegate = type => (e.Compile());
Expression<Func<Test, object>> e = o => o.Val;
sum.GetCalculateDelegate = _ => (e.Compile());
sum.DataSource = new DataSource(new object[] { new Test(1.5), new Test(2d), new Test(3.5), new Test(4.5) });

sum.Calculate(sum.DataSource).Should().Be(2.875);
Expand All @@ -86,9 +84,10 @@ public void AverageDoubleTest()
public void AverageTimeSpanTest()
{
var sum = new SubtotalSummaryFunc("average", 1);
Expression<Func<Test, object>> e = o => o.val;
sum.GetCalculateDelegate = type => (e.Compile());
sum.DataSource = new DataSource(new object[] { new Test(TimeSpan.FromHours(1)), new Test(TimeSpan.FromHours(2)), new Test(TimeSpan.FromHours(3)) });
Expression<Func<Test, object>> e = o => o.Val;
sum.GetCalculateDelegate = _ => (e.Compile());
sum.DataSource = new DataSource(new object[]
{ new Test(TimeSpan.FromHours(1)), new Test(TimeSpan.FromHours(2)), new Test(TimeSpan.FromHours(3)) });

sum.Calculate(sum.DataSource).Should().Be(TimeSpan.FromHours(2));
}
Expand All @@ -97,8 +96,8 @@ public void AverageTimeSpanTest()
public void MinIntTest()
{
var sum = new SubtotalSummaryFunc("min", 1);
Expression<Func<Test, object>> e = o => o.val;
sum.GetCalculateDelegate = type => (e.Compile());
Expression<Func<Test, object>> e = o => o.Val;
sum.GetCalculateDelegate = _ => (e.Compile());
sum.DataSource = new DataSource(new object[] { new Test(2), new Test(1), new Test(3) });

sum.Calculate(sum.DataSource).Should().Be(1);
Expand All @@ -108,8 +107,8 @@ public void MinIntTest()
public void MinDoubleTest()
{
var sum = new SubtotalSummaryFunc("min", 1);
Expression<Func<Test, object>> e = o => o.val;
sum.GetCalculateDelegate = type => (e.Compile());
Expression<Func<Test, object>> e = o => o.Val;
sum.GetCalculateDelegate = _ => (e.Compile());
sum.DataSource = new DataSource(new object[] { new Test(2d), new Test(0.5), new Test(3.5) });

sum.Calculate(sum.DataSource).Should().Be(0.5);
Expand All @@ -119,9 +118,13 @@ public void MinDoubleTest()
public void MinDateTimeTest()
{
var sum = new SubtotalSummaryFunc("min", 1);
Expression<Func<Test, object>> e = o => o.val;
sum.GetCalculateDelegate = type => (e.Compile());
sum.DataSource = new DataSource(new object[] { new Test(new DateTime(2017, 01, 01)), new Test(new DateTime(2016, 01, 01)), new Test(new DateTime(2018, 01, 01)) });
Expression<Func<Test, object>> e = o => o.Val;
sum.GetCalculateDelegate = _ => (e.Compile());
sum.DataSource = new DataSource(new object[]
{
new Test(new DateTime(2017, 01, 01)), new Test(new DateTime(2016, 01, 01)),
new Test(new DateTime(2018, 01, 01))
});

sum.Calculate(sum.DataSource).Should().Be(new DateTime(2016, 01, 01));
}
Expand All @@ -130,21 +133,24 @@ public void MinDateTimeTest()
public void StDevDoubleTest()
{
var sum = new SubtotalSummaryFunc("stdev", 1);
Expression<Func<Test, object>> e = o => o.val;
sum.GetCalculateDelegate = type => (e.Compile());
sum.DataSource = new DataSource(new object[] { new Test(10d), new Test(20d), new Test(30d), new Test(40d), new Test(50d), new Test(60d), new Test(70d) });
Expression<Func<Test, object>> e = o => o.Val;
sum.GetCalculateDelegate = _ => (e.Compile());
sum.DataSource = new DataSource(new object[]
{
new Test(10d), new Test(20d), new Test(30d), new Test(40d), new Test(50d), new Test(60d), new Test(70d)
});

((double)sum.Calculate(sum.DataSource)).Should().BeInRange(21.6, 21.61);
}

private class Test
{
public dynamic val;
public readonly dynamic Val;

public Test(dynamic val)
{
this.val = val;
Val = val;
}
}
}
}
}
Loading
Loading