-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from IowaComputerGurus/feature/auto-filter
Feature/auto filter
- Loading branch information
Showing
6 changed files
with
109 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 4 additions & 8 deletions
12
samples/NetCore.Utilities.SpreadsheetExample/Models/SecondExportData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,6 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
namespace NetCore.Utilities.SpreadsheetExample.Models; | ||
|
||
namespace NetCore.Utilities.SpreadsheetExample.Models | ||
internal class SecondExportData | ||
{ | ||
class SecondExportData | ||
{ | ||
} | ||
} | ||
|
||
} |
25 changes: 12 additions & 13 deletions
25
samples/NetCore.Utilities.SpreadsheetExample/Models/SimpleExportData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
using System; | ||
using ICG.NetCore.Utilities.Spreadsheet; | ||
|
||
namespace NetCore.Utilities.SpreadsheetExample.Models | ||
namespace NetCore.Utilities.SpreadsheetExample.Models; | ||
|
||
public class SimpleExportData | ||
{ | ||
public class SimpleExportData | ||
{ | ||
public string Title { get; set; } | ||
public string Title { get; set; } | ||
|
||
[SpreadsheetColumn("Due Date", format: "D")] | ||
public DateTime DueDate { get; set; } | ||
|
||
[SpreadsheetColumn("Due Date", format:"D")] | ||
public DateTime DueDate { get; set; } | ||
|
||
[SpreadsheetColumn("Total Cost", format:"C", formula: "SUM")] | ||
public decimal TotalCost { get; set; } | ||
[SpreadsheetColumn("Total Cost", format: "C", formula: "SUM")] | ||
public decimal TotalCost { get; set; } | ||
|
||
[SpreadsheetColumn("Testing Numbers", format:"F3")] | ||
public decimal TestingNumbers { get; set; } | ||
[SpreadsheetColumn("Testing Numbers", format: "F3")] | ||
public decimal TestingNumbers { get; set; } | ||
|
||
public string Notes { get; set; } | ||
} | ||
public string Notes { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,64 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using ICG.NetCore.Utilities.Spreadsheet; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NetCore.Utilities.SpreadsheetExample.Models; | ||
|
||
namespace NetCore.Utilities.SpreadsheetExample | ||
namespace NetCore.Utilities.SpreadsheetExample; | ||
|
||
internal class Program | ||
{ | ||
class Program | ||
private static void Main(string[] args) | ||
{ | ||
static void Main(string[] args) | ||
//Setup our DI Container | ||
var services = new ServiceCollection(); | ||
services.UseIcgNetCoreUtilitiesSpreadsheet(); | ||
var provider = services.BuildServiceProvider(); | ||
|
||
//Get our generator and export | ||
var exportGenerator = provider.GetRequiredService<ISpreadsheetGenerator>(); | ||
var exportDefinition = new SpreadsheetConfiguration<SimpleExportData> | ||
{ | ||
//Setup our DI Container | ||
var services = new ServiceCollection(); | ||
services.UseIcgNetCoreUtilitiesSpreadsheet(); | ||
var provider = services.BuildServiceProvider(); | ||
RenderTitle = true, | ||
DocumentTitle = "Sample Export of 100 Records", | ||
RenderSubTitle = true, | ||
DocumentSubTitle = "Showing the full options", | ||
ExportData = GetSampleExportData(100), | ||
WorksheetName = "Sample", | ||
FreezeHeaders = true, | ||
AutoFilterDataRows = true | ||
}; | ||
var fileContent = exportGenerator.CreateSingleSheetSpreadsheet(exportDefinition); | ||
File.WriteAllBytes("Sample.xlsx", fileContent); | ||
|
||
//Get our generator and export | ||
var exportGenerator = provider.GetRequiredService<ISpreadsheetGenerator>(); | ||
var exportDefinition = new SpreadsheetConfiguration<SimpleExportData> | ||
//Sample 2 sheet export | ||
var multiSheetDefinition = new MultisheetConfiguration() | ||
.WithSheet("Sheet 1", GetSampleExportData(100)) | ||
.WithSheet("Additional Sheet", GetSampleExportData(500), config => | ||
{ | ||
RenderTitle = true, | ||
DocumentTitle = "Sample Export of 100 Records", | ||
RenderSubTitle = true, | ||
DocumentSubTitle = "Showing the full options", | ||
ExportData = GetSampleExportData(100), | ||
WorksheetName = "Sample", | ||
FreezeHeaders = true | ||
}; | ||
var fileContent = exportGenerator.CreateSingleSheetSpreadsheet(exportDefinition); | ||
System.IO.File.WriteAllBytes("Sample.xlsx", fileContent); | ||
|
||
//Sample 2 sheet export | ||
var multiSheetDefinition = new MultisheetConfiguration() | ||
.WithSheet("Sheet 1", GetSampleExportData(100)) | ||
.WithSheet("Additional Sheet", GetSampleExportData(500), config => | ||
{ | ||
config.DocumentTitle = "Lots of data"; | ||
config.RenderTitle = true; | ||
config.FreezeHeaders = true; | ||
}); | ||
config.DocumentTitle = "Lots of data"; | ||
config.RenderTitle = true; | ||
config.FreezeHeaders = true; | ||
config.AutoFilterDataRows = true; | ||
}); | ||
|
||
var multiFileContent = exportGenerator.CreateMultiSheetSpreadsheet(multiSheetDefinition); | ||
System.IO.File.WriteAllBytes("Sample-Multi.xlsx", multiFileContent); | ||
Console.WriteLine("Files Created"); | ||
Console.ReadLine(); | ||
} | ||
var multiFileContent = exportGenerator.CreateMultiSheetSpreadsheet(multiSheetDefinition); | ||
File.WriteAllBytes("Sample-Multi.xlsx", multiFileContent); | ||
Console.WriteLine("Files Created"); | ||
Console.ReadLine(); | ||
} | ||
|
||
private static List<SimpleExportData> GetSampleExportData(int numberOfRecords) | ||
{ | ||
var listData = new List<SimpleExportData>(); | ||
for (var i = 0; i < numberOfRecords; i++) | ||
private static List<SimpleExportData> GetSampleExportData(int numberOfRecords) | ||
{ | ||
var listData = new List<SimpleExportData>(); | ||
for (var i = 0; i < numberOfRecords; i++) | ||
listData.Add(new SimpleExportData | ||
{ | ||
listData.Add(new SimpleExportData | ||
{DueDate = DateTime.Now.AddDays(i), Notes = $"Record {i} notes", TotalCost = 15m, TestingNumbers = 1234.4567289m, Title = $"Sample Data Row #{i}"}); | ||
} | ||
DueDate = DateTime.Now.AddDays(i), Notes = $"Record {i} notes", TotalCost = 15m, | ||
TestingNumbers = 1234.4567289m, Title = $"Sample Data Row #{i}" | ||
}); | ||
|
||
return listData; | ||
} | ||
return listData; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters