Skip to content

Commit c3c48c6

Browse files
Merge branch 'develop' into localizable_columns
2 parents 5066fa7 + fa422ba commit c3c48c6

File tree

13 files changed

+239
-120
lines changed

13 files changed

+239
-120
lines changed

.github/workflows/ci-build.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
fetch-depth: 0
2020

2121
- name: Ensure .NET Installed
22-
uses: actions/setup-dotnet@v3
22+
uses: actions/setup-dotnet@v4
2323
with:
2424
dotnet-version: 6.0.x
2525

@@ -46,10 +46,10 @@ jobs:
4646
env:
4747
solution-path: './src/NetCore.Utilities.Spreadsheet.sln'
4848
steps:
49-
- name: Set up JDK 11
49+
- name: Set up JDK 17
5050
uses: actions/setup-java@v3
5151
with:
52-
java-version: 11
52+
java-version: 17
5353
distribution: zulu
5454
- uses: actions/checkout@v4
5555
with:
@@ -89,7 +89,7 @@ jobs:
8989
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
9090
shell: powershell
9191
run: |
92-
.\.sonar\scanner\dotnet-sonarscanner begin /k:"IowaComputerGurus_netcore.utilities.spreadsheet" /o:"iowacomputergurus-github" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"
92+
.\.sonar\scanner\dotnet-sonarscanner begin /k:"IowaComputerGurus_netcore.utilities.spreadsheet" /o:"iowacomputergurus-github" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"
9393
dotnet restore "${{ env.solution-path }}"
9494
dotnet build "${{ env.solution-path }}" --no-restore --configuration Release -p:version=${{ steps.gitversion.outputs.majorMinorPatch }}
9595
dotnet test "${{ env.solution-path }}" --no-build --configuration Release --collect "XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover --logger "trx;LogFileName=unittests.trx"

.github/workflows/codeql.yml

-34
This file was deleted.

.github/workflows/release-build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
fetch-depth: 0
1919

2020
- name: Ensure .NET Installed
21-
uses: actions/setup-dotnet@v3
21+
uses: actions/setup-dotnet@v4
2222
with:
2323
dotnet-version: 6.0.x
2424

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ var exportDefinition = new SpreadsheetConfiguration<SimpleExportData>
4545
DocumentSubTitle = "Showing the full options",
4646
ExportData = GetSampleExportData(100),
4747
WorksheetName = "Sample",
48-
FreezePanes = true
48+
FreezePanes = true,
49+
AutoFilterDataRows = true
4950
};
5051
var fileContent = exportGenerator.CreateSingleSheetSpreadsheet(exportDefinition);
5152
System.IO.File.WriteAllBytes("Sample.xlsx", fileContent);
@@ -76,4 +77,6 @@ This package is primarily geared towards the exporting of lists of objects into
7677
* Data type formatting for Date & Currency fields
7778
* Auto-fit of all columns for display
7879
* The ability to freeze the header columns into a freeze pane for single sheet, or multi-sheet exports
79-
* Support for Curreny, Date, F0, F1, and F2 fixed date formats
80+
* The ability to add "Auto Filter" behavior to the data table portion of a sheet, while still supporting all other items
81+
* The ability to automatically add "simple formula" totals to columsn. (SUM, AVG, etc)
82+
* Support for Curreny, Date, F0, F1, F2, and F3 fixed data formats
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
1+
namespace NetCore.Utilities.SpreadsheetExample.Models;
42

5-
namespace NetCore.Utilities.SpreadsheetExample.Models
3+
internal class SecondExportData
64
{
7-
class SecondExportData
8-
{
9-
}
10-
}
5+
6+
}
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
using System;
2-
using System.ComponentModel;
32
using ICG.NetCore.Utilities.Spreadsheet;
43

5-
namespace NetCore.Utilities.SpreadsheetExample.Models
4+
namespace NetCore.Utilities.SpreadsheetExample.Models;
5+
6+
public class SimpleExportData
67
{
7-
public class SimpleExportData
8-
{
9-
public string Title { get; set; }
8+
public string Title { get; set; }
9+
10+
[SpreadsheetColumn("Due Date", format: "D")]
11+
public DateTime DueDate { get; set; }
12+
13+
[SpreadsheetColumn("Total Cost", format: "C", formula: "SUM")]
14+
public decimal TotalCost { get; set; }
1015

11-
[SpreadsheetColumn("Due Date", format:"D")]
12-
public DateTime DueDate { get; set; }
13-
14-
[SpreadsheetColumn("Total Cost", format:"C")]
15-
public decimal TotalCost { get; set; }
16+
[SpreadsheetColumn("Testing Numbers", format: "F3")]
17+
public decimal TestingNumbers { get; set; }
1618

17-
public string Notes { get; set; }
18-
}
19+
public string Notes { get; set; }
1920
}
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,64 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using ICG.NetCore.Utilities.Spreadsheet;
45
using Microsoft.Extensions.DependencyInjection;
56
using NetCore.Utilities.SpreadsheetExample.Models;
67

7-
namespace NetCore.Utilities.SpreadsheetExample
8+
namespace NetCore.Utilities.SpreadsheetExample;
9+
10+
internal class Program
811
{
9-
class Program
12+
private static void Main(string[] args)
1013
{
11-
static void Main(string[] args)
14+
//Setup our DI Container
15+
var services = new ServiceCollection();
16+
services.UseIcgNetCoreUtilitiesSpreadsheet();
17+
var provider = services.BuildServiceProvider();
18+
19+
//Get our generator and export
20+
var exportGenerator = provider.GetRequiredService<ISpreadsheetGenerator>();
21+
var exportDefinition = new SpreadsheetConfiguration<SimpleExportData>
1222
{
13-
//Setup our DI Container
14-
var services = new ServiceCollection();
15-
services.UseIcgNetCoreUtilitiesSpreadsheet();
16-
var provider = services.BuildServiceProvider();
23+
RenderTitle = true,
24+
DocumentTitle = "Sample Export of 100 Records",
25+
RenderSubTitle = true,
26+
DocumentSubTitle = "Showing the full options",
27+
ExportData = GetSampleExportData(100),
28+
WorksheetName = "Sample",
29+
FreezeHeaders = true,
30+
AutoFilterDataRows = true
31+
};
32+
var fileContent = exportGenerator.CreateSingleSheetSpreadsheet(exportDefinition);
33+
File.WriteAllBytes("Sample.xlsx", fileContent);
1734

18-
//Get our generator and export
19-
var exportGenerator = provider.GetRequiredService<ISpreadsheetGenerator>();
20-
var exportDefinition = new SpreadsheetConfiguration<SimpleExportData>
35+
//Sample 2 sheet export
36+
var multiSheetDefinition = new MultisheetConfiguration()
37+
.WithSheet("Sheet 1", GetSampleExportData(100))
38+
.WithSheet("Additional Sheet", GetSampleExportData(500), config =>
2139
{
22-
RenderTitle = true,
23-
DocumentTitle = "Sample Export of 100 Records",
24-
RenderSubTitle = true,
25-
DocumentSubTitle = "Showing the full options",
26-
ExportData = GetSampleExportData(100),
27-
WorksheetName = "Sample",
28-
FreezeHeaders = true
29-
};
30-
var fileContent = exportGenerator.CreateSingleSheetSpreadsheet(exportDefinition);
31-
System.IO.File.WriteAllBytes("Sample.xlsx", fileContent);
32-
33-
//Sample 2 sheet export
34-
var multiSheetDefinition = new MultisheetConfiguration()
35-
.WithSheet("Sheet 1", GetSampleExportData(100))
36-
.WithSheet("Additional Sheet", GetSampleExportData(500), config =>
37-
{
38-
config.DocumentTitle = "Lots of data";
39-
config.RenderTitle = true;
40-
config.FreezeHeaders = true;
41-
});
40+
config.DocumentTitle = "Lots of data";
41+
config.RenderTitle = true;
42+
config.FreezeHeaders = true;
43+
config.AutoFilterDataRows = true;
44+
});
4245

43-
var multiFileContent = exportGenerator.CreateMultiSheetSpreadsheet(multiSheetDefinition);
44-
System.IO.File.WriteAllBytes("Sample-Multi.xlsx", multiFileContent);
45-
Console.WriteLine("Files Created");
46-
Console.ReadLine();
47-
}
46+
var multiFileContent = exportGenerator.CreateMultiSheetSpreadsheet(multiSheetDefinition);
47+
File.WriteAllBytes("Sample-Multi.xlsx", multiFileContent);
48+
Console.WriteLine("Files Created");
49+
Console.ReadLine();
50+
}
4851

49-
private static List<SimpleExportData> GetSampleExportData(int numberOfRecords)
50-
{
51-
var listData = new List<SimpleExportData>();
52-
for (var i = 0; i < numberOfRecords; i++)
52+
private static List<SimpleExportData> GetSampleExportData(int numberOfRecords)
53+
{
54+
var listData = new List<SimpleExportData>();
55+
for (var i = 0; i < numberOfRecords; i++)
56+
listData.Add(new SimpleExportData
5357
{
54-
listData.Add(new SimpleExportData
55-
{DueDate = DateTime.Now.AddDays(i), Notes = $"Record {i} notes", TotalCost = 15m, Title = $"Sample Data Row #{i}"});
56-
}
58+
DueDate = DateTime.Now.AddDays(i), Notes = $"Record {i} notes", TotalCost = 15m,
59+
TestingNumbers = 1234.4567289m, Title = $"Sample Data Row #{i}"
60+
});
5761

58-
return listData;
59-
}
62+
return listData;
6063
}
61-
}
64+
}

src/NetCore.Utilities.Spreadsheet.Tests/OpenXmlSpreadsheetGeneratorTests.cs

+24
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ private static Faker<TestExportRecord> GetTestExportRecordFaker() =>
160160
.RuleFor(i => i.Fixed0, f => f.Random.Decimal(0, 100))
161161
.RuleFor(i => i.Fixed1, f => f.Random.Decimal(0, 100))
162162
.RuleFor(i => i.Fixed2, f => f.Random.Decimal(0, 100))
163+
.RuleFor(i => i.Fixed3, f=> f.Random.Decimal(0, 100))
163164
;
164165

165166
private static Faker<DifferentTestExportRecord> GetDifferentTestExportRecordFaker() =>
@@ -265,6 +266,29 @@ public void CreateSingleWorksheet_Returning_Bytes_Should_Work()
265266
File.WriteAllBytes(sheetPath, result);
266267
ValidateExportedSheet(ms, 1, testData);
267268
}
269+
270+
[Fact]
271+
public void CreateSingleWorksheet_With_Formula()
272+
{
273+
using var ms = new MemoryStream();
274+
var testData = new List<SampleExportRecordWithFormula>()
275+
{
276+
new() { RecordTitle = "test record 1", RecordAmount = 10, RecordSize = 444 },
277+
new() { RecordTitle = "test record 2", RecordAmount = 20, RecordSize = 5 },
278+
new() { RecordTitle = "test record 3", RecordAmount = 30, RecordSize = 67 },
279+
new() { RecordTitle = "test record 4", RecordAmount = 3, RecordSize = 477 },
280+
};
281+
282+
_spreadsheetGenerator.CreateSingleSheetSpreadsheet(ms, new SpreadsheetConfiguration<SampleExportRecordWithFormula>
283+
{
284+
WorksheetName = "Test Sheet",
285+
AutoSizeColumns = true,
286+
ExportData = testData
287+
});
288+
289+
ms.Seek(0, SeekOrigin.Begin);
290+
ms.Should().NotHaveLength(0);
291+
}
268292

269293
/*
270294
* This uses the OpenXmlSpreadsheetParser to attempt to pull the data out of the spreadsheet we just

src/NetCore.Utilities.Spreadsheet.Tests/SampleExportRecord.cs

+16
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ public class TestExportRecord
9292
[SpreadsheetColumn(displayName: "Fixed2", format: ColumnFormats.Fixed2)]
9393
[SpreadsheetImportColumn(19)]
9494
public decimal Fixed2 { get; set; }
95+
96+
[SpreadsheetColumn(displayName: "Fixed3", format: ColumnFormats.Fixed3)]
97+
[SpreadsheetImportColumn(20)]
98+
public decimal Fixed3 { get; set; }
9599
}
96100

97101
public class DifferentTestExportRecord
@@ -118,4 +122,16 @@ public class LocalizedSampleExportRecord
118122
{
119123
[SpreadsheetColumn(ResourceFileType = typeof(TestResources), ResourceKey = nameof(TestResources.LocalizedColumn))]
120124
public string? RecordTitle { get; set; }
125+
}
126+
127+
public class SampleExportRecordWithFormula
128+
{
129+
[DisplayName("Title")]
130+
public string? RecordTitle { get; set; }
131+
132+
[SpreadsheetColumn("Amount", Formula = "SUM")]
133+
public decimal RecordAmount { get; set; }
134+
135+
[SpreadsheetColumn("Size", Formula = "MAX")]
136+
public decimal RecordSize { get; set; }
121137
}

0 commit comments

Comments
 (0)