diff --git a/.gitignore b/.gitignore index d580317..8c16d86 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,242 @@ -################################################################################ -# This .gitignore file was automatically created by Microsoft(R) Visual Studio. -################################################################################ - -/Excelerator/Excelerator.Examples/bin/Debug -/Excelerator/Excelerator.Examples/obj/Debug -/Excelerator/Excelerator.Common/bin/Debug -/Excelerator/Excelerator.Common/obj/Debug -/Excelerator/Excelerator.ClosedXml/bin/Debug -/Excelerator/Excelerator.ClosedXml/obj/Debug -/Excelerator/packages +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +[Xx]64/ +[Xx]86/ +[Bb]uild/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml + +# TODO: Un-comment the next line if you do not want to checkin +# your web deploy settings because they may include unencrypted +# passwords +#*.pubxml +*.publishproj + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directory +AppPackages/ +BundleArtifacts/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +# [Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# LightSwitch generated files +GeneratedArtifacts/ +ModelManifest.xml + +# Paket dependency manager +.paket/paket.exe + +# FAKE - F# Make +.fake/ diff --git a/Excelerator/Excelerator.ClosedXml/Excelerator.ClosedXml.csproj b/Excelerator.ClosedXml/Excelerator.ClosedXml.csproj similarity index 78% rename from Excelerator/Excelerator.ClosedXml/Excelerator.ClosedXml.csproj rename to Excelerator.ClosedXml/Excelerator.ClosedXml.csproj index e84173c..263beb9 100644 --- a/Excelerator/Excelerator.ClosedXml/Excelerator.ClosedXml.csproj +++ b/Excelerator.ClosedXml/Excelerator.ClosedXml.csproj @@ -1,17 +1,16 @@  - + Debug AnyCPU - {B4678384-40B3-4FDD-8630-C88605C492B9} + {491716B9-5349-4BDA-B3FA-85C485DBBCBF} Library Properties Excelerator.ClosedXml Excelerator.ClosedXml - v4.0 + v4.6.2 512 - true @@ -33,11 +32,9 @@ ..\packages\ClosedXML.0.86.0\lib\net40\ClosedXML.dll - True ..\packages\DocumentFormat.OpenXml.2.5\lib\DocumentFormat.OpenXml.dll - True @@ -51,25 +48,17 @@ + - {73e17926-1326-413a-abc3-f7af36133eba} + {75d30f7d-1c33-42e0-be51-128d712ec3a1} Excelerator.Common - - - \ No newline at end of file diff --git a/Excelerator/Excelerator.ClosedXml/Export/ClosedXmlExcelGenerator.cs b/Excelerator.ClosedXml/Export/ClosedXmlExcelGenerator.cs similarity index 64% rename from Excelerator/Excelerator.ClosedXml/Export/ClosedXmlExcelGenerator.cs rename to Excelerator.ClosedXml/Export/ClosedXmlExcelGenerator.cs index c40d478..1b920b8 100644 --- a/Excelerator/Excelerator.ClosedXml/Export/ClosedXmlExcelGenerator.cs +++ b/Excelerator.ClosedXml/Export/ClosedXmlExcelGenerator.cs @@ -1,30 +1,30 @@ -using ClosedXML.Excel; -using Excelerator.ClosedXml.Export.Mappings; -using Excelerator.Export; -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; +using ClosedXML.Excel; +using Excelerator.ClosedXml.Export.Mappings; +using Excelerator.Export; namespace Excelerator.ClosedXml.Export { public class ClosedXmlExcelGenerator : IExcelGenerator where TModel : class { - private int _startCol = 1; - private int _startRow = 1; + private readonly int _startCol = 1; + private readonly int _startRow = 1; protected XLWorkbook Workbook { get; set; } - public string WorksheetName { get; set; } protected int StartRow { get; set; } protected int StartColumn { get; set; } + public string WorksheetName { get; set; } - protected virtual XLWorkbook GenerateWorkbook(List> columnsMd, List> data) + public MemoryStream Generate(List> columnsMetadata, IEnumerable> data) { - var workbook = Workbook ?? new XLWorkbook(); + var ms = new MemoryStream(); + var workbook = Workbook ?? new XLWorkbook(XLEventTracking.Disabled); var worksheet = workbook.Worksheets.Any() ? workbook.Worksheet(1) : workbook.Worksheets.Add(string.IsNullOrEmpty(WorksheetName) ? "Sheet1" : WorksheetName); - var row = StartRow == 0 ? _startRow : StartRow; // Set headers @@ -34,42 +34,31 @@ protected virtual XLWorkbook GenerateWorkbook(List> worksheet.Cell(i, j).Value = md.Header; worksheet.Cell(i, j).Style.Alignment.Horizontal = md.HorizontalAlignment.Map(); worksheet.Cell(i, j).Style.Alignment.Vertical = md.VerticalAlignment.Map(); - }, row, columnsMd); + }, row, columnsMetadata); row++; if (data != null) - { foreach (var val in data) { Process((i, j, md) => { var value = md.Value(val.Data); - worksheet.Cell(i, j).Value = value ?? string.Empty; - worksheet.Cell(i, j).Style.Alignment.Horizontal = md.HorizontalAlignment.Map(); - worksheet.Cell(i, j).Style.Alignment.Vertical = md.VerticalAlignment.Map(); - }, row, columnsMd); + var cell = worksheet.Cell(i, j); + cell.Value = value ?? string.Empty; + cell.Style.Alignment.Horizontal = md.HorizontalAlignment.Map(); + cell.Style.Alignment.Vertical = md.VerticalAlignment.Map(); + }, row, columnsMetadata); row++; } - } - return workbook; - } - - public virtual MemoryStream Generate(List> columnsMd, List> data) - { - var ms = new MemoryStream(); - var workbook = GenerateWorkbook(columnsMd, data); workbook.SaveAs(ms); ms.Position = 0; return ms; } - private void Process(Action> action, int currentRow, List> columns) { var startCol = StartColumn == 0 ? _startCol : StartColumn; - for (int i = _startCol; i <= columns.Count; i++) + for (var i = _startCol; i <= columns.Count; i++) action(currentRow, i, columns.ElementAt(i - 1)); } - - } -} +} \ No newline at end of file diff --git a/Excelerator/Excelerator.ClosedXml/Export/Mappings/ClosedXmlMappings.cs b/Excelerator.ClosedXml/Export/Mappings/ClosedXmlMappings.cs similarity index 100% rename from Excelerator/Excelerator.ClosedXml/Export/Mappings/ClosedXmlMappings.cs rename to Excelerator.ClosedXml/Export/Mappings/ClosedXmlMappings.cs diff --git a/Excelerator.ClosedXml/Import/ClosedXmlExcelImporter.cs b/Excelerator.ClosedXml/Import/ClosedXmlExcelImporter.cs new file mode 100644 index 0000000..84da2e1 --- /dev/null +++ b/Excelerator.ClosedXml/Import/ClosedXmlExcelImporter.cs @@ -0,0 +1,114 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using ClosedXML.Excel; +using Excelerator.Common.Import; +using Excelerator.Common.Import.Exceptions; + +namespace Excelerator.ClosedXml.Import +{ + public class ClosedXmlExcelImporter : IExcelImporter where T : class, IRowModelBase, new() + { + public ImportResults Import(List md, MemoryStream ms) + { + var res = new ImportResults(); + var wb = new XLWorkbook(ms); + if (!wb.Worksheets.Any()) + throw new ExcelImporterException("Workbook doesn't contain any worksheet"); + + var sh = wb.Worksheet(1); + var headerCell = SearchHeader(sh, md); + var colsOrder = GetColumnsOrder(sh, md); + + ProcessRows(row => + { + var item = new T {Row = row}; + md.ForEach(metadata => + { + dynamic cmd = md; + var cellValue = sh.Cell(row, colsOrder[metadata.Title]).Value; + cmd.SetModelPropertyValue(item, cmd.CellValue(cellValue)); + }); + res.Values.Add(item); + }, headerCell.Address.RowNumber + 1, GetRowsCount(sh)); + return res; + } + + private IXLCell GetStartCell(IXLWorksheet sheet) + { + return sheet.RangeUsed().FirstCell(); + } + + private int GetColumnsCount(IXLWorksheet sheet) + { + return sheet.RangeUsed().ColumnCount(); + } + + private int GetRowsCount(IXLWorksheet sheet) + { + return sheet.RangeUsed().RowCount(); + } + + private IXLCell SearchHeader(IXLWorksheet sheet, List mdList) + { + var startCell = GetStartCell(sheet); + var startRow = startCell.Address.RowNumber; + var startCol = startCell.Address.ColumnNumber; + var headers = mdList.Select(md => md.Title).ToList(); + var colsCount = GetColumnsCount(sheet); + var rowsCount = GetRowsCount(sheet); + + var headerRow = -1; + var headerCol = -1; + ProcessRows(row => + { + if (headerRow > 0) return; + var isHeaderRow = true; + ProcessCols((i, j) => + { + var cellVal = sheet.Cell(i, j).GetValue(); + if (!isHeaderRow || string.IsNullOrEmpty(cellVal)) + return; + var isCellContainsAnyHeader = headers.Any(h => h.Equals(cellVal, StringComparison.InvariantCultureIgnoreCase)); + if (headerCol == -1 && isCellContainsAnyHeader) + headerCol = j; + if (!isCellContainsAnyHeader) + isHeaderRow = false; + }, row, startCol, colsCount); + if (isHeaderRow) headerRow = row + 1; + }, startRow, rowsCount); + + return sheet.Cell(headerRow, startCol); + } + + private Dictionary GetColumnsOrder(IXLWorksheet sheet, List mdList) + { + var res = new Dictionary(); + var headerCell = SearchHeader(sheet, mdList); + var startCell = GetStartCell(sheet); + var startCol = startCell.Address.ColumnNumber; + var colsCount = GetColumnsCount(sheet); + var headers = mdList.Select(md => md.Title).ToList(); + ProcessCols((i, j) => + { + var cellVal = sheet.Cell(i, j).GetValue(); + if (string.IsNullOrEmpty(cellVal)) return; + var targetHeader = headers.FirstOrDefault(h => h.Equals(cellVal, StringComparison.InvariantCultureIgnoreCase)); + if (targetHeader != null && !res.ContainsKey(targetHeader)) + res.Add(targetHeader, j); + }, headerCell.Address.RowNumber, startCol, colsCount); + return res; + } + + private void ProcessRows(Action action, int startRow, int rowsCount) + { + for (var i = startRow; i <= rowsCount; i++) action(i); + } + + private void ProcessCols(Action action, int row, int startColumn, int columnsCount) + { + for (var i = startColumn; i <= startColumn + columnsCount; i++) action(row, i); + } + } +} \ No newline at end of file diff --git a/Excelerator/Excelerator.ClosedXml/Properties/AssemblyInfo.cs b/Excelerator.ClosedXml/Properties/AssemblyInfo.cs similarity index 80% rename from Excelerator/Excelerator.ClosedXml/Properties/AssemblyInfo.cs rename to Excelerator.ClosedXml/Properties/AssemblyInfo.cs index 145b64c..9a5a2b9 100644 --- a/Excelerator/Excelerator.ClosedXml/Properties/AssemblyInfo.cs +++ b/Excelerator.ClosedXml/Properties/AssemblyInfo.cs @@ -2,7 +2,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -// General Information about an assembly is controlled through the following +// General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Excelerator.ClosedXml")] @@ -10,27 +10,27 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Excelerator.ClosedXml")] -[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyCopyright("Copyright © 2017")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("b4678384-40b3-4fdd-8630-c88605c492b9")] +[assembly: Guid("491716b9-5349-4bda-b3fa-85c485dbbcbf")] // Version information for an assembly consists of the following four values: // // Major Version -// Minor Version +// Minor Version // Build Number // Revision // -// You can specify all the values or you can default the Build and Revision Numbers +// You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.1.1")] -[assembly: AssemblyFileVersion("0.1.1")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Excelerator/Excelerator.ClosedXml/packages.config b/Excelerator.ClosedXml/packages.config similarity index 96% rename from Excelerator/Excelerator.ClosedXml/packages.config rename to Excelerator.ClosedXml/packages.config index 39de25e..c397b63 100644 --- a/Excelerator/Excelerator.ClosedXml/packages.config +++ b/Excelerator.ClosedXml/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/Excelerator/Excelerator.Common/Enums/HorizontalCellAlignmentValues.cs b/Excelerator.Common/Enums/HorizontalCellAlignmentValues.cs similarity index 100% rename from Excelerator/Excelerator.Common/Enums/HorizontalCellAlignmentValues.cs rename to Excelerator.Common/Enums/HorizontalCellAlignmentValues.cs diff --git a/Excelerator/Excelerator.Common/Enums/VerticalCellAlignmentValues.cs b/Excelerator.Common/Enums/VerticalCellAlignmentValues.cs similarity index 100% rename from Excelerator/Excelerator.Common/Enums/VerticalCellAlignmentValues.cs rename to Excelerator.Common/Enums/VerticalCellAlignmentValues.cs diff --git a/Excelerator/Excelerator.Common/Excelerator.Common.csproj b/Excelerator.Common/Excelerator.Common.csproj similarity index 79% rename from Excelerator/Excelerator.Common/Excelerator.Common.csproj rename to Excelerator.Common/Excelerator.Common.csproj index e20ad69..e37cc5e 100644 --- a/Excelerator/Excelerator.Common/Excelerator.Common.csproj +++ b/Excelerator.Common/Excelerator.Common.csproj @@ -1,17 +1,16 @@  - + Debug AnyCPU - {73E17926-1326-413A-ABC3-F7AF36133EBA} + {75D30F7D-1C33-42E0-BE51-128D712EC3A1} Library Properties Excelerator.Common Excelerator.Common - v4.0 + v4.6.2 512 - true @@ -50,17 +49,15 @@ + + + + + + + - - - + - \ No newline at end of file diff --git a/Excelerator/Excelerator.Common/Export/ExcelColumnMetadata.cs b/Excelerator.Common/Export/ExcelColumnMetadata.cs similarity index 100% rename from Excelerator/Excelerator.Common/Export/ExcelColumnMetadata.cs rename to Excelerator.Common/Export/ExcelColumnMetadata.cs diff --git a/Excelerator/Excelerator.Common/Export/ExcelRowModel.cs b/Excelerator.Common/Export/ExcelRowModel.cs similarity index 100% rename from Excelerator/Excelerator.Common/Export/ExcelRowModel.cs rename to Excelerator.Common/Export/ExcelRowModel.cs diff --git a/Excelerator/Excelerator.Common/Export/IExcelGenerator.cs b/Excelerator.Common/Export/IExcelGenerator.cs similarity index 68% rename from Excelerator/Excelerator.Common/Export/IExcelGenerator.cs rename to Excelerator.Common/Export/IExcelGenerator.cs index 0a82084..d559ee1 100644 --- a/Excelerator/Excelerator.Common/Export/IExcelGenerator.cs +++ b/Excelerator.Common/Export/IExcelGenerator.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.IO; namespace Excelerator.Export @@ -7,6 +8,6 @@ public interface IExcelGenerator where TModel : class { string WorksheetName { get; set; } - MemoryStream Generate(List> columns, List> data); + MemoryStream Generate(List> columnsMetadata, IEnumerable> data); } } diff --git a/Excelerator/Excelerator.Common/Export/WorkbookData.cs b/Excelerator.Common/Export/WorkbookData.cs similarity index 100% rename from Excelerator/Excelerator.Common/Export/WorkbookData.cs rename to Excelerator.Common/Export/WorkbookData.cs diff --git a/Excelerator/Excelerator.Common/Export/WorkbookSettings.cs b/Excelerator.Common/Export/WorkbookSettings.cs similarity index 100% rename from Excelerator/Excelerator.Common/Export/WorkbookSettings.cs rename to Excelerator.Common/Export/WorkbookSettings.cs diff --git a/Excelerator/Excelerator.Common/Export/WorksheetData.cs b/Excelerator.Common/Export/WorksheetData.cs similarity index 100% rename from Excelerator/Excelerator.Common/Export/WorksheetData.cs rename to Excelerator.Common/Export/WorksheetData.cs diff --git a/Excelerator/Excelerator.Common/Export/WorksheetSettings.cs b/Excelerator.Common/Export/WorksheetSettings.cs similarity index 100% rename from Excelerator/Excelerator.Common/Export/WorksheetSettings.cs rename to Excelerator.Common/Export/WorksheetSettings.cs diff --git a/Excelerator.Common/Import/ExcelColumnImportMetadata.cs b/Excelerator.Common/Import/ExcelColumnImportMetadata.cs new file mode 100644 index 0000000..80797eb --- /dev/null +++ b/Excelerator.Common/Import/ExcelColumnImportMetadata.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Excelerator.Common.Import +{ + public class ExcelColumnImportMetadata + { + public ExcelColumnImportMetadata() { } + public ExcelColumnImportMetadata(string title) + { + Title = title; + } + public string Title { get; set; } + public Func CellValue { get; set; } + public Action SetModelPropertyValue { get; set; } + + } + + public class ExcelColumnImportMetadata : ExcelColumnImportMetadata + { + public ExcelColumnImportMetadata() : base() { } + public ExcelColumnImportMetadata(string title) : base(title) { } + public new Func CellValue { get; set; } + public new Action SetModelPropertyValue { get; set; } + } +} diff --git a/Excelerator.Common/Import/Exceptions/ExcelImporterException.cs b/Excelerator.Common/Import/Exceptions/ExcelImporterException.cs new file mode 100644 index 0000000..b1bd3d0 --- /dev/null +++ b/Excelerator.Common/Import/Exceptions/ExcelImporterException.cs @@ -0,0 +1,11 @@ +using System; + +namespace Excelerator.Common.Import.Exceptions +{ + public class ExcelImporterException : ApplicationException + { + public ExcelImporterException(string message) : base(message) + { + } + } +} \ No newline at end of file diff --git a/Excelerator.Common/Import/IExcelImporter.cs b/Excelerator.Common/Import/IExcelImporter.cs new file mode 100644 index 0000000..7e435a5 --- /dev/null +++ b/Excelerator.Common/Import/IExcelImporter.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Excelerator.Common.Import +{ + public interface IExcelImporter + where T : class, IRowModelBase, new() + { + ImportResults Import(List md, MemoryStream ms); + } + public class ImportResults : ImportResults + where T : IRowModelBase + { + public ImportResults() + { + Values = new List(); + Errors = new List>(); + } + public List Values { get; set; } + public List> Errors { get; set; } + } +} diff --git a/Excelerator.Common/Import/IRowModelBase.cs b/Excelerator.Common/Import/IRowModelBase.cs new file mode 100644 index 0000000..5bfc29e --- /dev/null +++ b/Excelerator.Common/Import/IRowModelBase.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Excelerator.Common.Import +{ + public interface IRowModelBase + { + int Row { get; set; } + } +} diff --git a/Excelerator.Common/Import/ImportError.cs b/Excelerator.Common/Import/ImportError.cs new file mode 100644 index 0000000..241983b --- /dev/null +++ b/Excelerator.Common/Import/ImportError.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Excelerator.Common.Import +{ + public class ImportError + { + public T Value { get; set; } + public ValidationResult ValidationResult { get; set; } + } +} diff --git a/Excelerator.Common/Import/ImportResults.cs b/Excelerator.Common/Import/ImportResults.cs new file mode 100644 index 0000000..9c6c598 --- /dev/null +++ b/Excelerator.Common/Import/ImportResults.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Excelerator.Common.Import +{ + public class ImportResults { } +} diff --git a/Excelerator.Common/Import/ValidationResult.cs b/Excelerator.Common/Import/ValidationResult.cs new file mode 100644 index 0000000..6093e8a --- /dev/null +++ b/Excelerator.Common/Import/ValidationResult.cs @@ -0,0 +1,8 @@ +namespace Excelerator.Common.Import +{ + public class ValidationResult + { + public bool IsValid { get; set; } + public string Message { get; set; } + } +} \ No newline at end of file diff --git a/Excelerator/Excelerator.Common/Properties/AssemblyInfo.cs b/Excelerator.Common/Properties/AssemblyInfo.cs similarity index 80% rename from Excelerator/Excelerator.Common/Properties/AssemblyInfo.cs rename to Excelerator.Common/Properties/AssemblyInfo.cs index 8e16447..6238c81 100644 --- a/Excelerator/Excelerator.Common/Properties/AssemblyInfo.cs +++ b/Excelerator.Common/Properties/AssemblyInfo.cs @@ -2,7 +2,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -// General Information about an assembly is controlled through the following +// General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Excelerator.Common")] @@ -10,27 +10,27 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Excelerator.Common")] -[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyCopyright("Copyright © 2017")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("73e17926-1326-413a-abc3-f7af36133eba")] +[assembly: Guid("75d30f7d-1c33-42e0-be51-128d712ec3a1")] // Version information for an assembly consists of the following four values: // // Major Version -// Minor Version +// Minor Version // Build Number // Revision // -// You can specify all the values or you can default the Build and Revision Numbers +// You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.1.1")] -[assembly: AssemblyFileVersion("0.1.1")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Excelerator/Excelerator.Examples/DependencyResolver/DefaultModule.cs b/Excelerator.Examples/DependencyResolver/DefaultModule.cs similarity index 52% rename from Excelerator/Excelerator.Examples/DependencyResolver/DefaultModule.cs rename to Excelerator.Examples/DependencyResolver/DefaultModule.cs index 16d6d75..7c41cc8 100644 --- a/Excelerator/Excelerator.Examples/DependencyResolver/DefaultModule.cs +++ b/Excelerator.Examples/DependencyResolver/DefaultModule.cs @@ -1,5 +1,7 @@ using Excelerator.Examples.Export.Example1.Generator; using Excelerator.Examples.Export.Example1.Model; +using Excelerator.Examples.Export.Example2.Generator; +using Excelerator.Examples.Export.Example2.Model; using Excelerator.Export; using Ninject.Modules; @@ -9,7 +11,8 @@ public class DefaultModule : NinjectModule { public override void Load() { - Kernel.Rebind>().To(); + //Kernel.Rebind>().To(); + Kernel.Rebind>().To(); } } } diff --git a/Excelerator/Excelerator.Examples/Excelerator.Examples.csproj b/Excelerator.Examples/Excelerator.Examples.csproj similarity index 59% rename from Excelerator/Excelerator.Examples/Excelerator.Examples.csproj rename to Excelerator.Examples/Excelerator.Examples.csproj index 6909533..9b03b57 100644 --- a/Excelerator/Excelerator.Examples/Excelerator.Examples.csproj +++ b/Excelerator.Examples/Excelerator.Examples.csproj @@ -1,21 +1,18 @@  - + Debug AnyCPU - {F5C6F9AA-3BE8-4263-BB47-6C6094E57EEA} + {ABFE93E2-EC28-4B79-850D-58D2FD93DF81} Exe Properties Excelerator.Examples Excelerator.Examples - v4.0 + v4.6.2 512 - true - - AnyCPU true full false @@ -25,7 +22,6 @@ 4 - AnyCPU pdbonly true bin\Release\ @@ -33,10 +29,18 @@ prompt 4 + + + + + ..\packages\ClosedXML.0.86.0\lib\net40\ClosedXML.dll + + + ..\packages\DocumentFormat.OpenXml.2.5\lib\DocumentFormat.OpenXml.dll + ..\packages\Ninject.3.2.2.0\lib\net45-full\Ninject.dll - True @@ -46,37 +50,49 @@ + + ..\packages\WindowsBase.4.6.1055.0\lib\WindowsBase.dll + True + + + + + + + + + + + - - + + PreserveNewest + - {b4678384-40b3-4fdd-8630-c88605c492b9} + {491716b9-5349-4bda-b3fa-85c485dbbcbf} Excelerator.ClosedXml - {73e17926-1326-413a-abc3-f7af36133eba} + {75d30f7d-1c33-42e0-be51-128d712ec3a1} Excelerator.Common + + {1864a702-8f24-4e2f-8a68-b890f14fc8eb} + Excelerator.OpenXml + - \ No newline at end of file diff --git a/Excelerator/Excelerator.Examples/Export/Example1/Example1.cs b/Excelerator.Examples/Export/Example1/Example1.cs similarity index 92% rename from Excelerator/Excelerator.Examples/Export/Example1/Example1.cs rename to Excelerator.Examples/Export/Example1/Example1.cs index db3c57b..6b3d246 100644 --- a/Excelerator/Excelerator.Examples/Export/Example1/Example1.cs +++ b/Excelerator.Examples/Export/Example1/Example1.cs @@ -28,7 +28,7 @@ public void Execute() }), 20); _generator.WorksheetName = "Example1"; - SaveToFile(_generator.Generate(metadata, data), $"{ExportExamplesPath}\\example1.xlsx"); + //SaveToFile(_generator.Generate(metadata, data), $"{ExportExamplesPath}\\example1.xlsx"); } #region Helpers diff --git a/Excelerator/Excelerator.Examples/Export/Example1/Generator/Example1Generator.cs b/Excelerator.Examples/Export/Example1/Generator/Example1Generator.cs similarity index 65% rename from Excelerator/Excelerator.Examples/Export/Example1/Generator/Example1Generator.cs rename to Excelerator.Examples/Export/Example1/Generator/Example1Generator.cs index 9ed3edb..b2b67fc 100644 --- a/Excelerator/Excelerator.Examples/Export/Example1/Generator/Example1Generator.cs +++ b/Excelerator.Examples/Export/Example1/Generator/Example1Generator.cs @@ -3,5 +3,5 @@ namespace Excelerator.Examples.Export.Example1.Generator { - public class Example1Generator : ClosedXmlExcelGenerator { } + //public class Example1Generator : ClosedXmlExcelGenerator { } } diff --git a/Excelerator/Excelerator.Examples/Export/Example1/Model/Example1Model.cs b/Excelerator.Examples/Export/Example1/Model/Example1Model.cs similarity index 100% rename from Excelerator/Excelerator.Examples/Export/Example1/Model/Example1Model.cs rename to Excelerator.Examples/Export/Example1/Model/Example1Model.cs diff --git a/Excelerator.Examples/Export/Example2/Example2.cs b/Excelerator.Examples/Export/Example2/Example2.cs new file mode 100644 index 0000000..724e877 --- /dev/null +++ b/Excelerator.Examples/Export/Example2/Example2.cs @@ -0,0 +1,219 @@ +using Excelerator.Examples.Export.Example1.Model; +using Excelerator.Export; +using System; +using System.Collections.Generic; +using System.Threading; +using Excelerator.Examples.Export.Example2.Model; + +namespace Excelerator.Examples.Export.Example2 +{ + public class Example2 : ExportExampleBase + { + //private readonly IExcelGenerator _generator; + private readonly IExcelGenerator _openXmlGenerator; + public Example2(IExcelGenerator openXmlGenerator) + { + //_generator = generator; + _openXmlGenerator = openXmlGenerator; + } + + public void Execute() + { + var metadata = new List>() + { + new ExcelColumnMetadata() {Header = "Prop1", Value = _ => _.Prop1}, + new ExcelColumnMetadata() {Header = "Prop2", Value = _ => _.Prop2}, + new ExcelColumnMetadata() {Header = "Prop3", Value = _ => _.Prop3}, + new ExcelColumnMetadata() {Header = "Prop4", Value = _ => _.Prop4}, + new ExcelColumnMetadata() {Header = "Prop5", Value = _ => _.Prop5}, + new ExcelColumnMetadata() {Header = "Prop6", Value = _ => _.Prop6}, + new ExcelColumnMetadata() {Header = "Prop7", Value = _ => _.Prop7}, + new ExcelColumnMetadata() {Header = "Prop8", Value = _ => _.Prop8}, + new ExcelColumnMetadata() {Header = "Prop9", Value = _ => _.Prop9}, + new ExcelColumnMetadata() {Header = "Prop10", Value = _ => _.Prop10}, + new ExcelColumnMetadata() {Header = "Prop11", Value = _ => _.Prop11}, + new ExcelColumnMetadata() {Header = "Prop12", Value = _ => _.Prop12}, + new ExcelColumnMetadata() {Header = "Prop13", Value = _ => _.Prop13}, + new ExcelColumnMetadata() {Header = "Prop14", Value = _ => _.Prop14}, + new ExcelColumnMetadata() {Header = "Prop15", Value = _ => _.Prop15}, + new ExcelColumnMetadata() {Header = "Prop16", Value = _ => _.Prop16}, + new ExcelColumnMetadata() {Header = "Prop17", Value = _ => _.Prop17}, + new ExcelColumnMetadata() {Header = "Prop18", Value = _ => _.Prop18}, + new ExcelColumnMetadata() {Header = "Prop19", Value = _ => _.Prop19}, + new ExcelColumnMetadata() {Header = "Prop20", Value = _ => _.Prop20}, + new ExcelColumnMetadata() {Header = "Prop21", Value = _ => _.Prop21}, + new ExcelColumnMetadata() {Header = "Prop22", Value = _ => _.Prop22}, + new ExcelColumnMetadata() {Header = "Prop23", Value = _ => _.Prop23}, + new ExcelColumnMetadata() {Header = "Prop24", Value = _ => _.Prop24}, + new ExcelColumnMetadata() {Header = "Prop25", Value = _ => _.Prop25}, + new ExcelColumnMetadata() {Header = "Prop26", Value = _ => _.Prop26}, + new ExcelColumnMetadata() {Header = "Prop27", Value = _ => _.Prop27}, + new ExcelColumnMetadata() {Header = "Prop28", Value = _ => _.Prop28}, + new ExcelColumnMetadata() {Header = "Prop29", Value = _ => _.Prop29}, + new ExcelColumnMetadata() {Header = "Prop30", Value = _ => _.Prop30}, + }; + + var metadata2 = new List>() + { + new ExcelColumnMetadata() {Header = "Prop1", Value = _ => _.Prop1}, + new ExcelColumnMetadata() {Header = "Prop2", Value = _ => _.Prop2}, + new ExcelColumnMetadata() {Header = "Prop3", Value = _ => _.Prop3}, + new ExcelColumnMetadata() {Header = "Prop4", Value = _ => _.Prop4}, + new ExcelColumnMetadata() {Header = "Prop5", Value = _ => _.Prop5}, + new ExcelColumnMetadata() {Header = "Prop6", Value = _ => _.Prop6}, + new ExcelColumnMetadata() {Header = "Prop7", Value = _ => _.Prop7}, + new ExcelColumnMetadata() {Header = "Prop8", Value = _ => _.Prop8}, + new ExcelColumnMetadata() {Header = "Prop9", Value = _ => _.Prop9}, + new ExcelColumnMetadata() {Header = "Prop10", Value = _ => _.Prop10}, + new ExcelColumnMetadata() {Header = "Prop11", Value = _ => _.Prop11}, + new ExcelColumnMetadata() {Header = "Prop12", Value = _ => _.Prop12}, + new ExcelColumnMetadata() {Header = "Prop13", Value = _ => _.Prop13}, + new ExcelColumnMetadata() {Header = "Prop14", Value = _ => _.Prop14}, + new ExcelColumnMetadata() {Header = "Prop15", Value = _ => _.Prop15}, + new ExcelColumnMetadata() {Header = "Prop16", Value = _ => _.Prop16}, + new ExcelColumnMetadata() {Header = "Prop17", Value = _ => _.Prop17}, + new ExcelColumnMetadata() {Header = "Prop18", Value = _ => _.Prop18}, + new ExcelColumnMetadata() {Header = "Prop19", Value = _ => _.Prop19}, + new ExcelColumnMetadata() {Header = "Prop20", Value = _ => _.Prop20}, + new ExcelColumnMetadata() {Header = "Prop21", Value = _ => _.Prop21}, + new ExcelColumnMetadata() {Header = "Prop22", Value = _ => _.Prop22}, + new ExcelColumnMetadata() {Header = "Prop23", Value = _ => _.Prop23}, + new ExcelColumnMetadata() {Header = "Prop24", Value = _ => _.Prop24}, + new ExcelColumnMetadata() {Header = "Prop25", Value = _ => _.Prop25}, + new ExcelColumnMetadata() {Header = "Prop26", Value = _ => _.Prop26}, + new ExcelColumnMetadata() {Header = "Prop27", Value = _ => _.Prop27}, + new ExcelColumnMetadata() {Header = "Prop28", Value = _ => _.Prop28}, + new ExcelColumnMetadata() {Header = "Prop29", Value = _ => _.Prop29}, + new ExcelColumnMetadata() {Header = "Prop30", Value = _ => _.Prop30}, + }; + + var data = new List>(); + var data2 = new List>(); + var total = 1000000; + for (var i = 0; i <= total; i++) + { + + } + + + Iterate(i => + { + data.Add(new ExcelRowModel() { Data = GetModel(i) }); + data2.Add(new ExcelRowModel() { Data = GetModel2(i) }); + if (i % 100 == 0) + Console.WriteLine(i); + }, 1000000); + + //_generator.WorksheetName = "Example2"; + //SaveToFile(_generator.Generate(metadata, data), $"{ExportExamplesPath}\\example2.xlsx"); + //var ms = _generator.Generate(metadata, data); + + var ms = _openXmlGenerator.Generate(metadata2, Iterate((i) => new ExcelRowModel() { Data = GetModel2(i) }, 1000000)); + + + //Iterate(i => + //{ + + // if (i % 100 == 0) Console.WriteLine(i); + // yield return new ExcelRowModel() { Data = GetModel2(i) }; + //}, 1000000)); + SaveToFile(ms, $"{ExportExamplesPath}\\example21.xlsx"); + } + + + + #region Helpers + + private IEnumerable> Iterate(Func> action, int maxValue) + { + for (int i = 0; i < maxValue; i++) + { + yield return action(i); + } + } + + private void Iterate(Action action, int maxValue) + { + for (int i = 0; i < maxValue; i++) + { + action(i); + } + } + + private Example2Model GetModel(int i) + { + return new Example2Model() + { + Prop1 = $"prop1_{i}", + Prop2 = $"prop2_{i}", + Prop3 = $"prop3_{i}", + Prop4 = $"prop4_{i}", + Prop5 = $"prop5_{i}", + Prop6 = $"prop6_{i}", + Prop7 = $"prop7_{i}", + Prop8 = $"prop8_{i}", + Prop9 = $"prop9_{i}", + Prop10 = $"prop10_{i}", + Prop11 = $"prop11_{i}", + Prop12 = $"prop12_{i}", + Prop13 = $"prop13_{i}", + Prop14 = $"prop14_{i}", + Prop15 = $"prop15_{i}", + Prop16 = $"prop16_{i}", + Prop17 = $"prop17_{i}", + Prop18 = $"prop18_{i}", + Prop19 = $"prop19_{i}", + Prop20 = $"prop20_{i}", + Prop21 = $"prop21_{i}", + Prop22 = $"prop22_{i}", + Prop23 = $"prop23_{i}", + Prop24 = $"prop24_{i}", + Prop25 = $"prop25_{i}", + Prop26 = $"prop26_{i}", + Prop27 = $"prop27_{i}", + Prop28 = $"prop28_{i}", + Prop29 = $"prop29_{i}", + Prop30 = $"prop30_{i}", + }; + } + + private Example21Model GetModel2(int i) + { + return new Example21Model() + { + Prop1 = $"prop1_{i}", + Prop2 = $"prop2_{i}", + Prop3 = $"prop3_{i}", + Prop4 = $"prop4_{i}", + Prop5 = $"prop5_{i}", + Prop6 = $"prop6_{i}", + Prop7 = $"prop7_{i}", + Prop8 = $"prop8_{i}", + Prop9 = $"prop9_{i}", + Prop10 = $"prop10_{i}", + Prop11 = $"prop11_{i}", + Prop12 = $"prop12_{i}", + Prop13 = $"prop13_{i}", + Prop14 = $"prop14_{i}", + Prop15 = $"prop15_{i}", + Prop16 = $"prop16_{i}", + Prop17 = $"prop17_{i}", + Prop18 = $"prop18_{i}", + Prop19 = $"prop19_{i}", + Prop20 = $"prop20_{i}", + Prop21 = $"prop21_{i}", + Prop22 = $"prop22_{i}", + Prop23 = $"prop23_{i}", + Prop24 = $"prop24_{i}", + Prop25 = $"prop25_{i}", + Prop26 = $"prop26_{i}", + Prop27 = $"prop27_{i}", + Prop28 = $"prop28_{i}", + Prop29 = $"prop29_{i}", + Prop30 = $"prop30_{i}", + }; + } + + #endregion + } +} diff --git a/Excelerator.Examples/Export/Example2/Generator/Example2Generator.cs b/Excelerator.Examples/Export/Example2/Generator/Example2Generator.cs new file mode 100644 index 0000000..49c4c2f --- /dev/null +++ b/Excelerator.Examples/Export/Example2/Generator/Example2Generator.cs @@ -0,0 +1,12 @@ +using Excelerator.ClosedXml.Export; +using Excelerator.Examples.Export.Example1.Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Excelerator.Examples.Export.Example2.Generator +{ + //public class Example2Generator : ClosedXmlExcelGenerator { } +} diff --git a/Excelerator.Examples/Export/Example2/Generator/Example2OpenXmlGenerator.cs b/Excelerator.Examples/Export/Example2/Generator/Example2OpenXmlGenerator.cs new file mode 100644 index 0000000..2c15767 --- /dev/null +++ b/Excelerator.Examples/Export/Example2/Generator/Example2OpenXmlGenerator.cs @@ -0,0 +1,8 @@ +using Excelerator.Examples.Export.Example1.Model; +using Excelerator.Examples.Export.Example2.Model; +using Excelerator.OpenXml.Export; + +namespace Excelerator.Examples.Export.Example2.Generator +{ + public class Example2OpenXmlGenerator : OpenXmlExcelGenerator { } +} diff --git a/Excelerator.Examples/Export/Example2/Model/Example2Model.cs b/Excelerator.Examples/Export/Example2/Model/Example2Model.cs new file mode 100644 index 0000000..a4a4425 --- /dev/null +++ b/Excelerator.Examples/Export/Example2/Model/Example2Model.cs @@ -0,0 +1,36 @@ +namespace Excelerator.Examples.Export.Example1.Model +{ + public class Example2Model + { + public string Prop1 { get; set; } + public string Prop2 { get; set; } + public string Prop3 { get; set; } + public string Prop4 { get; set; } + public string Prop5 { get; set; } + public string Prop6 { get; set; } + public string Prop7 { get; set; } + public string Prop8 { get; set; } + public string Prop9 { get; set; } + public string Prop10{ get; set; } + public string Prop11{ get; set; } + public string Prop12{ get; set; } + public string Prop13{ get; set; } + public string Prop14{ get; set; } + public string Prop15{ get; set; } + public string Prop16{ get; set; } + public string Prop17{ get; set; } + public string Prop18{ get; set; } + public string Prop19{ get; set; } + public string Prop20{ get; set; } + public string Prop21{ get; set; } + public string Prop22{ get; set; } + public string Prop23{ get; set; } + public string Prop24{ get; set; } + public string Prop25{ get; set; } + public string Prop26{ get; set; } + public string Prop27{ get; set; } + public string Prop28{ get; set; } + public string Prop29{ get; set; } + public string Prop30{ get; set; } + } +} diff --git a/Excelerator.Examples/Export/Example2/Model/Example2_1Model.cs b/Excelerator.Examples/Export/Example2/Model/Example2_1Model.cs new file mode 100644 index 0000000..0d40c6b --- /dev/null +++ b/Excelerator.Examples/Export/Example2/Model/Example2_1Model.cs @@ -0,0 +1,8 @@ +using Excelerator.Examples.Export.Example1.Model; + +namespace Excelerator.Examples.Export.Example2.Model +{ + public class Example21Model : Example2Model + { + } +} diff --git a/Excelerator/Excelerator.Examples/Export/ExportExampleBase.cs b/Excelerator.Examples/Export/ExportExampleBase.cs similarity index 100% rename from Excelerator/Excelerator.Examples/Export/ExportExampleBase.cs rename to Excelerator.Examples/Export/ExportExampleBase.cs diff --git a/Excelerator.Examples/Import/Example1/Data/example1.xlsx b/Excelerator.Examples/Import/Example1/Data/example1.xlsx new file mode 100644 index 0000000..21e4e9c Binary files /dev/null and b/Excelerator.Examples/Import/Example1/Data/example1.xlsx differ diff --git a/Excelerator.Examples/Import/Example1/Example1.cs b/Excelerator.Examples/Import/Example1/Example1.cs new file mode 100644 index 0000000..4c315e1 --- /dev/null +++ b/Excelerator.Examples/Import/Example1/Example1.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Excelerator.Common.Import; +using Excelerator.Examples.Import.Example1.Model; + +namespace Excelerator.Examples.Import.Example1 +{ + public class Example1 : ImportExampleBase + { + private readonly IExcelImporter _importer; + public Example1(IExcelImporter importer) + { + _importer = importer; + } + + public void Execute() + { + var md = new List() + { + new ExcelColumnImportMetadata("Фамилия") { CellValue = GetString, SetModelPropertyValue = (model, value) => model.Value1 = value }, + new ExcelColumnImportMetadata("Имя") { CellValue = (obj)=> Convert.ToInt64(obj), SetModelPropertyValue = (model, value) => model.Value2 = value }, + }; + + + + var ms = new MemoryStream(); + _importer.Import(md, ms); + + } + private string GetString(object obj) + { + var res = Convert.ToString(obj); + return res.Trim(); + } + } +} diff --git a/Excelerator.Examples/Import/Example1/Importer/Example1Importer.cs b/Excelerator.Examples/Import/Example1/Importer/Example1Importer.cs new file mode 100644 index 0000000..7f0d0d2 --- /dev/null +++ b/Excelerator.Examples/Import/Example1/Importer/Example1Importer.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Excelerator.ClosedXml.Import; +using Excelerator.Examples.Import.Example1.Model; + +namespace Excelerator.Examples.Import.Example1.Importer +{ + public class Example1Importer : ClosedXmlExcelImporter + { + } +} diff --git a/Excelerator.Examples/Import/Example1/Model/Example1RowModel.cs b/Excelerator.Examples/Import/Example1/Model/Example1RowModel.cs new file mode 100644 index 0000000..f7915dd --- /dev/null +++ b/Excelerator.Examples/Import/Example1/Model/Example1RowModel.cs @@ -0,0 +1,11 @@ +using Excelerator.Common.Import; + +namespace Excelerator.Examples.Import.Example1.Model +{ + public class Example1RowModel : IRowModelBase + { + public string Value1 { get; set; } + public long Value2 { get; set; } + public int Row { get; set; } + } +} \ No newline at end of file diff --git a/Excelerator.Examples/Import/ImportExampleBase.cs b/Excelerator.Examples/Import/ImportExampleBase.cs new file mode 100644 index 0000000..0e9da2f --- /dev/null +++ b/Excelerator.Examples/Import/ImportExampleBase.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Excelerator.Examples.Import +{ + public class ImportExampleBase + { + } +} diff --git a/Excelerator/Excelerator.Examples/Program.cs b/Excelerator.Examples/Program.cs similarity index 66% rename from Excelerator/Excelerator.Examples/Program.cs rename to Excelerator.Examples/Program.cs index 68b4b7e..6de1378 100644 --- a/Excelerator/Excelerator.Examples/Program.cs +++ b/Excelerator.Examples/Program.cs @@ -1,24 +1,26 @@ -using Excelerator.Examples.DependencyResolver; -using Excelerator.Examples.Export.Example1; +using System.IO; +using Excelerator.Examples.DependencyResolver; +using Excelerator.Examples.Export.Example2; using Ninject; -using System.IO; namespace Excelerator.Examples { - public class Program + public static class Program { - private static IKernel _kernel; - static void Main(string[] args) + + public static void Main(string[] args) { CheckDirs(); _kernel = new StandardKernel(new DefaultModule()); - // Example1 - Get().Execute(); + //Get().Execute(); + + Get().Execute(); } #region Helpers + private static T Get() { return _kernel.Get(); @@ -30,8 +32,7 @@ private static void CheckDirs() if (!Directory.Exists("Examples\\Export")) Directory.CreateDirectory("Examples\\Export"); if (!Directory.Exists("Examples\\Import")) Directory.CreateDirectory("Examples\\Import"); } - #endregion - + #endregion } -} +} \ No newline at end of file diff --git a/Excelerator/Excelerator.Examples/Properties/AssemblyInfo.cs b/Excelerator.Examples/Properties/AssemblyInfo.cs similarity index 80% rename from Excelerator/Excelerator.Examples/Properties/AssemblyInfo.cs rename to Excelerator.Examples/Properties/AssemblyInfo.cs index e800596..c429a4c 100644 --- a/Excelerator/Excelerator.Examples/Properties/AssemblyInfo.cs +++ b/Excelerator.Examples/Properties/AssemblyInfo.cs @@ -2,7 +2,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -// General Information about an assembly is controlled through the following +// General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Excelerator.Examples")] @@ -10,27 +10,27 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Excelerator.Examples")] -[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyCopyright("Copyright © 2017")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("f5c6f9aa-3be8-4263-bb47-6c6094e57eea")] +[assembly: Guid("abfe93e2-ec28-4b79-850d-58d2fd93df81")] // Version information for an assembly consists of the following four values: // // Major Version -// Minor Version +// Minor Version // Build Number // Revision // -// You can specify all the values or you can default the Build and Revision Numbers +// You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.1.0")] -[assembly: AssemblyFileVersion("0.1.0")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Excelerator.Examples/packages.config b/Excelerator.Examples/packages.config new file mode 100644 index 0000000..4376def --- /dev/null +++ b/Excelerator.Examples/packages.config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Excelerator.OpenXml/Class1.cs b/Excelerator.OpenXml/Class1.cs new file mode 100644 index 0000000..19d7eaf --- /dev/null +++ b/Excelerator.OpenXml/Class1.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Excelerator.OpenXml +{ + public class Class1 + { + } +} diff --git a/Excelerator.OpenXml/Excelerator.OpenXml.csproj b/Excelerator.OpenXml/Excelerator.OpenXml.csproj new file mode 100644 index 0000000..1f62e17 --- /dev/null +++ b/Excelerator.OpenXml/Excelerator.OpenXml.csproj @@ -0,0 +1,65 @@ + + + + + Debug + AnyCPU + {1864A702-8F24-4E2F-8A68-B890F14FC8EB} + Library + Properties + Excelerator.OpenXml + Excelerator.OpenXml + v4.6.2 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\DocumentFormat.OpenXml.2.5\lib\DocumentFormat.OpenXml.dll + + + + + + + + + + + ..\packages\WindowsBase.4.6.1055.0\lib\WindowsBase.dll + True + + + + + + + + + + + {75d30f7d-1c33-42e0-be51-128d712ec3a1} + Excelerator.Common + + + + + + + \ No newline at end of file diff --git a/Excelerator.OpenXml/Export/Mappings/OpenXmlMappings.cs b/Excelerator.OpenXml/Export/Mappings/OpenXmlMappings.cs new file mode 100644 index 0000000..7e2db89 --- /dev/null +++ b/Excelerator.OpenXml/Export/Mappings/OpenXmlMappings.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Excelerator.OpenXml.Export.Mappings +{ + class OpenXmlMappings + { + } +} diff --git a/Excelerator.OpenXml/Export/OpenXmlExcelGenerator.cs b/Excelerator.OpenXml/Export/OpenXmlExcelGenerator.cs new file mode 100644 index 0000000..1c910c4 --- /dev/null +++ b/Excelerator.OpenXml/Export/OpenXmlExcelGenerator.cs @@ -0,0 +1,105 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Spreadsheet; +using Excelerator.Export; + +namespace Excelerator.OpenXml.Export +{ + public class OpenXmlExcelGenerator : IExcelGenerator + where TModel : class + { + public string WorksheetName { get; set; } + + public MemoryStream Generate(List> columns, IEnumerable> data) + { + var colsCount = columns.Count; + //var rowsCount = data.Count; + + var ms = new MemoryStream(); + using (SpreadsheetDocument myDoc = SpreadsheetDocument.Create(ms, SpreadsheetDocumentType.Workbook)) + { + WorkbookPart workbookPart = myDoc.AddWorkbookPart(); + //WorksheetPart worksheetPart = workbookPart.AddNewPart<>() WorksheetParts.First(); + //string origninalSheetId = workbookPart.GetIdOfPart(worksheetPart); + + WorksheetPart replacementPart = workbookPart.AddNewPart(); + string replacementPartId = workbookPart.GetIdOfPart(replacementPart); + + //OpenXmlReader reader = OpenXmlReader.Create(worksheetPart); + OpenXmlWriter writer = OpenXmlWriter.Create(replacementPart); + + Row r = new Row(); + Cell c = new Cell(); + CellFormula f = new CellFormula(); + f.CalculateCell = true; + f.Text = "RAND()"; + c.Append(f); + CellValue v = new CellValue(); + c.Append(v); + + + writer.WriteStartElement(new SheetData()); + foreach (var el in data) + { + writer.WriteStartElement(r); + for (int col = 0; col < colsCount; col++) + { + writer.WriteElement(c); + } + writer.WriteEndElement(); + + } + writer.WriteEndElement(); + + //while (reader.Read()) + //{ + // if (reader.ElementType == typeof(SheetData)) + // { + // if (reader.IsEndElement) + // continue; + // writer.WriteStartElement(new SheetData()); + + // for (int row = 0; row < rowsCount; row++) + // { + // writer.WriteStartElement(r); + // for (int col = 0; col < colsCount; col++) + // { + // writer.WriteElement(c); + // } + // writer.WriteEndElement(); + // } + + // writer.WriteEndElement(); + // } + // else + // { + // if (reader.IsStartElement) + // { + // writer.WriteStartElement(reader); + // } + // else if (reader.IsEndElement) + // { + // writer.WriteEndElement(); + // } + // } + //} + //reader.Close(); + writer.Close(); + + //var sheet = workbookPart.Workbook.Descendants().First(s => s.Id.Value.Equals(origninalSheetId)); + //sheet.Id.Value = replacementPartId; + //workbookPart.DeletePart(worksheetPart); + + } + ms.Position = 0; + return ms; + } + } +} diff --git a/Excelerator.OpenXml/Properties/AssemblyInfo.cs b/Excelerator.OpenXml/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..6512871 --- /dev/null +++ b/Excelerator.OpenXml/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Excelerator.OpenXml")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Excelerator.OpenXml")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("1864a702-8f24-4e2f-8a68-b890f14fc8eb")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Excelerator.OpenXml/packages.config b/Excelerator.OpenXml/packages.config new file mode 100644 index 0000000..f9a8b7d --- /dev/null +++ b/Excelerator.OpenXml/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/Excelerator.sln b/Excelerator.sln new file mode 100644 index 0000000..a2d16bd --- /dev/null +++ b/Excelerator.sln @@ -0,0 +1,40 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26228.9 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Excelerator.Common", "Excelerator.Common\Excelerator.Common.csproj", "{75D30F7D-1C33-42E0-BE51-128D712EC3A1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Excelerator.ClosedXml", "Excelerator.ClosedXml\Excelerator.ClosedXml.csproj", "{491716B9-5349-4BDA-B3FA-85C485DBBCBF}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Excelerator.Examples", "Excelerator.Examples\Excelerator.Examples.csproj", "{ABFE93E2-EC28-4B79-850D-58D2FD93DF81}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Excelerator.OpenXml", "Excelerator.OpenXml\Excelerator.OpenXml.csproj", "{1864A702-8F24-4E2F-8A68-B890F14FC8EB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {75D30F7D-1C33-42E0-BE51-128D712EC3A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {75D30F7D-1C33-42E0-BE51-128D712EC3A1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {75D30F7D-1C33-42E0-BE51-128D712EC3A1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {75D30F7D-1C33-42E0-BE51-128D712EC3A1}.Release|Any CPU.Build.0 = Release|Any CPU + {491716B9-5349-4BDA-B3FA-85C485DBBCBF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {491716B9-5349-4BDA-B3FA-85C485DBBCBF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {491716B9-5349-4BDA-B3FA-85C485DBBCBF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {491716B9-5349-4BDA-B3FA-85C485DBBCBF}.Release|Any CPU.Build.0 = Release|Any CPU + {ABFE93E2-EC28-4B79-850D-58D2FD93DF81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ABFE93E2-EC28-4B79-850D-58D2FD93DF81}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ABFE93E2-EC28-4B79-850D-58D2FD93DF81}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ABFE93E2-EC28-4B79-850D-58D2FD93DF81}.Release|Any CPU.Build.0 = Release|Any CPU + {1864A702-8F24-4E2F-8A68-B890F14FC8EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1864A702-8F24-4E2F-8A68-B890F14FC8EB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1864A702-8F24-4E2F-8A68-B890F14FC8EB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1864A702-8F24-4E2F-8A68-B890F14FC8EB}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Excelerator/.vs/Excelerator/v14/.suo b/Excelerator/.vs/Excelerator/v14/.suo deleted file mode 100644 index 70a2112..0000000 Binary files a/Excelerator/.vs/Excelerator/v14/.suo and /dev/null differ diff --git a/Excelerator/Excelerator.ClosedXml/.nuget/Excelerator.ClosedXml.nuspec b/Excelerator/Excelerator.ClosedXml/.nuget/Excelerator.ClosedXml.nuspec deleted file mode 100644 index 2eb04b3..0000000 --- a/Excelerator/Excelerator.ClosedXml/.nuget/Excelerator.ClosedXml.nuspec +++ /dev/null @@ -1,24 +0,0 @@ - - - - Excelerator.ClosedXml - 0.1.1 - $title$ - ETR - ETR - Excelerator.ClosedXml - http://etr-nuget-01/docs/etr.framework/icons/$title$.png - false - Copyright 2017 - - - - - - - - - - - - diff --git a/Excelerator/Excelerator.Common/.nuget/Excelerator.Common.nuspec b/Excelerator/Excelerator.Common/.nuget/Excelerator.Common.nuspec deleted file mode 100644 index c9292c1..0000000 --- a/Excelerator/Excelerator.Common/.nuget/Excelerator.Common.nuspec +++ /dev/null @@ -1,20 +0,0 @@ - - - - Excelerator.Common - 0.1.1 - $title$ - ETR - ETR - Excelerator.Common - http://etr-nuget-01/docs/etr.framework/icons/$title$.png - false - Copyright 2017 - - - - - - - - diff --git a/Excelerator/Excelerator.Examples/App.config b/Excelerator/Excelerator.Examples/App.config deleted file mode 100644 index 74ade9d..0000000 --- a/Excelerator/Excelerator.Examples/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/Excelerator/Excelerator.Examples/packages.config b/Excelerator/Excelerator.Examples/packages.config deleted file mode 100644 index 60512fc..0000000 --- a/Excelerator/Excelerator.Examples/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/Excelerator/Excelerator.sln b/Excelerator/Excelerator.sln deleted file mode 100644 index 49447ec..0000000 --- a/Excelerator/Excelerator.sln +++ /dev/null @@ -1,34 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Excelerator.Common", "Excelerator.Common\Excelerator.Common.csproj", "{73E17926-1326-413A-ABC3-F7AF36133EBA}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Excelerator.ClosedXml", "Excelerator.ClosedXml\Excelerator.ClosedXml.csproj", "{B4678384-40B3-4FDD-8630-C88605C492B9}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Excelerator.Examples", "Excelerator.Examples\Excelerator.Examples.csproj", "{F5C6F9AA-3BE8-4263-BB47-6C6094E57EEA}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {73E17926-1326-413A-ABC3-F7AF36133EBA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {73E17926-1326-413A-ABC3-F7AF36133EBA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {73E17926-1326-413A-ABC3-F7AF36133EBA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {73E17926-1326-413A-ABC3-F7AF36133EBA}.Release|Any CPU.Build.0 = Release|Any CPU - {B4678384-40B3-4FDD-8630-C88605C492B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B4678384-40B3-4FDD-8630-C88605C492B9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B4678384-40B3-4FDD-8630-C88605C492B9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B4678384-40B3-4FDD-8630-C88605C492B9}.Release|Any CPU.Build.0 = Release|Any CPU - {F5C6F9AA-3BE8-4263-BB47-6C6094E57EEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F5C6F9AA-3BE8-4263-BB47-6C6094E57EEA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F5C6F9AA-3BE8-4263-BB47-6C6094E57EEA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F5C6F9AA-3BE8-4263-BB47-6C6094E57EEA}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal