-
Notifications
You must be signed in to change notification settings - Fork 0
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 #3 from doroudi/Feature/improve_export_performance
improve export performance
- Loading branch information
Showing
16 changed files
with
221 additions
and
151 deletions.
There are no files selected for viewing
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using ExcelMapper.ExcelMapper; | ||
using ExcelMapper.Test.Models; | ||
using ExcelMapper.Validations; | ||
|
||
namespace ExcelMapper.Test.MapperProfiles | ||
{ | ||
public class EmployeeMapperProfile : ExcelImportMapper<Employee> | ||
{ | ||
public EmployeeMapperProfile() | ||
{ | ||
CreateMap() | ||
.ForMember(x => x.Id, | ||
opt => opt.MapFromCol("A").UseValidation(GeneralValidations.NotNull)) | ||
.ForMember(x => x.Name, | ||
opt => opt.MapFromCol("B").UseValidation(GeneralValidations.NotNull)) | ||
.ForMember(x => x.Family, | ||
opt => opt.MapFromCol("C").UseValidation(GeneralValidations.NotNull)) | ||
.ForMember(x => x.JoinDate, | ||
opt => opt.MapFromCol("D").UseValidation(GeneralValidations.NotNull)) | ||
.ForMember(x => x.NationalId, | ||
opt => opt.MapFromCol("E").UseValidation(GeneralValidations.NotNull)) | ||
.ForMember(x => x.Address, | ||
opt => opt.MapFromCol("F").UseValidation(GeneralValidations.NotNull)); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using ExcelMapper.ExcelExporter; | ||
using ExcelMapper.Test.Models; | ||
using NPOI.SS.UserModel; | ||
|
||
namespace ExcelMapper.Test.MapperProfiles | ||
{ | ||
public class ExportProfile: ExportMapper<Employee> | ||
{ | ||
public ExportProfile(IWorkbook workbook): base(workbook) | ||
{ | ||
CreateMap() | ||
.ForColumn("A", x => x.Name, opt => opt.WithTitle("Name")) | ||
.ForColumn("B", x => x.Family, opt => opt.WithTitle("Family")) | ||
.ForColumn("C", x => x.BirthDate, opt => opt.WithTitle("BirthDate").UseAction(ConvertToPersian)) | ||
.ForColumn("D", x => x.Address, opt => opt.WithTitle("Address")) | ||
.ForColumn("E", x => x.Name, opt => opt.WithTitle("NAME").UseAction(x => x.ToUpper())); | ||
// .ForColumn("B", opt => opt.MapFrom<Employee>(x => x.Name)); | ||
} | ||
|
||
private string ConvertToPersian(DateTime arg) | ||
{ | ||
return arg.ToShortDateString(); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ExcelMapper.Test.Models | ||
{ | ||
public class Employee | ||
{ | ||
public string Id { get; set; } | ||
public string Name { get; set; } | ||
public string Family { get; set; } | ||
public string Mobile { get; set; } | ||
public string NationalId { get; set; } | ||
public string Address { get; set; } | ||
public int Grade { get; set; } | ||
public DateTime JoinDate { get; set; } | ||
public DateTime BirthDate { get; set; } | ||
|
||
public override string ToString() | ||
{ | ||
return $"({Name} {Family}, {BirthDate:D})"; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using ExcelMapper; | ||
using ExcelMapper.ExcelParser; | ||
using ExcelMapper.Logger; | ||
using ExcelMapper.Test.MapperProfiles; | ||
using ExcelMapper.Test.Models; | ||
|
||
var fileName = @"AppData\data.xlsx"; | ||
ExcelParser<Employee> parser = new (new FileInfo(fileName), new EmployeeMapperProfile()); | ||
var employees = parser.GetItems(); | ||
|
||
|
||
foreach (var emplyee in employees) | ||
{ | ||
Console.WriteLine(emplyee); | ||
} | ||
|
||
var logger = new ExcelLogger(fileName,"EF"); | ||
logger.LogInvalidColumns(parser.InvalidRows); | ||
|
||
var exporter = new ExcelWriter(); | ||
|
||
exporter.AddSheet( | ||
new ExportProfile(exporter.WorkBook), | ||
x => x.SetRtl().UseData(employees).UseDefaultHeaderStyle().Build() | ||
); | ||
|
||
exporter.SaveToFile("D:\\excel\\EXPORT.xlsx"); |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\ExcelMapper\YummyCode.ExcelMapper.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="AppData\data.xlsx"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
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
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
Oops, something went wrong.