├── ExcelWizard.Tests ├── Usings.cs ├── UnitTest1.cs ├── ExcelWizard.Tests.csproj └── Models │ └── EWCell │ └── CellBuilderTests.cs ├── screenshots ├── Screenshot-1.png ├── Screenshot-2.png ├── Screenshot-3.png ├── Screenshot-4.png ├── Screenshot-5.png └── accounts-excel-template-report.png ├── templates └── ComplexExcelTemplate.xlsx ├── samples ├── BlazorApp │ ├── wwwroot │ │ ├── favicon.ico │ │ ├── icon-192.png │ │ ├── css │ │ │ ├── open-iconic │ │ │ │ ├── font │ │ │ │ │ ├── fonts │ │ │ │ │ │ ├── open-iconic.eot │ │ │ │ │ │ ├── open-iconic.otf │ │ │ │ │ │ ├── open-iconic.ttf │ │ │ │ │ │ └── open-iconic.woff │ │ │ │ │ └── css │ │ │ │ │ │ └── open-iconic-bootstrap.min.css │ │ │ │ ├── ICON-LICENSE │ │ │ │ ├── README.md │ │ │ │ └── FONT-LICENSE │ │ │ └── app.css │ │ ├── sample-data │ │ │ └── weather.json │ │ └── index.html │ ├── Pages │ │ ├── Counter.razor │ │ ├── Index.razor │ │ └── FetchData.razor │ ├── _Imports.razor │ ├── Shared │ │ ├── MainLayout.razor │ │ ├── SurveyPrompt.razor │ │ ├── NavMenu.razor.css │ │ ├── NavMenu.razor │ │ └── MainLayout.razor.css │ ├── App.razor │ ├── Program.cs │ ├── BlazorApp.csproj │ ├── Properties │ │ └── launchSettings.json │ └── AppExcelReportModel.cs └── ApiApp │ ├── appsettings.Development.json │ ├── SimorghReportModels │ ├── AccountDto.cs │ ├── Multiplex.cs │ ├── SummaryAccount.cs │ ├── VoucherStatementItem.cs │ └── VoucherStatementResult.cs │ ├── appsettings.json │ ├── DocExampleModels │ ├── AccountSalaryCode.cs │ ├── AccountSharingData.cs │ ├── AccountsReportDto.cs │ └── AccountDebitCredit.cs │ ├── WeatherForecast.cs │ ├── ApiApp.csproj │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Service │ └── ISimorghExcelBuilderService.cs │ ├── User.cs │ └── Controllers │ └── WeatherForecastController.cs ├── ExcelWizard ├── Models │ ├── EWCell │ │ ├── CellBuilderContracts.cs │ │ ├── CellContentType.cs │ │ ├── CellStyle.cs │ │ ├── CellLocation.cs │ │ ├── Cell.cs │ │ └── CellBuilder.cs │ ├── EWSheet │ │ ├── SheetDirection.cs │ │ ├── SheetVisibility.cs │ │ ├── AllSheetsDefaultStyle.cs │ │ ├── SheetStyle.cs │ │ ├── Sheet.cs │ │ ├── SheetBuilder.cs │ │ └── SheetBuilderContracts.cs │ ├── EWStyles │ │ ├── FontWeight.cs │ │ ├── TextAlign.cs │ │ ├── LineStyle.cs │ │ ├── TextFont.cs │ │ └── Border.cs │ ├── EWColumn │ │ ├── ColumnWidthCalculationType.cs │ │ ├── ColumnStyle.cs │ │ └── ColumnWidth.cs │ ├── EWGridLayout │ │ ├── GridLayoutExcelModel.cs │ │ ├── GridExcelSheet.cs │ │ ├── ExcelSheetColumnAttribute.cs │ │ └── ExcelSheetAttribute.cs │ ├── GeneratedExcelFile.cs │ ├── EWMerge │ │ ├── MergedBoundaryLocation.cs │ │ ├── MergedCells.cs │ │ ├── MergeBuilderContracts.cs │ │ └── MergeBuilder.cs │ ├── EWRow │ │ ├── RowStyle.cs │ │ ├── RowBuilderContracts.cs │ │ ├── RowBuilder.cs │ │ └── Row.cs │ ├── ExcelModel.cs │ ├── EWExcel │ │ ├── SheetBinding.cs │ │ ├── ExcelBuilderContracts.cs │ │ └── ExcelBuilder.cs │ ├── EWTable │ │ ├── TableStyle.cs │ │ ├── ExcelTableColumnAttribute.cs │ │ ├── ExcelTableAttribute.cs │ │ ├── TableBuilderContracts.cs │ │ ├── Table.cs │ │ └── TableBuilder.cs │ └── ProtectionLevel.cs ├── Service │ ├── IExcelWizardService.cs │ └── FakeBlazorDownloadFileService.cs ├── ExcelWizard.csproj └── ExcelWizardExtensions.cs ├── LICENSE ├── ExcelWizard.sln.DotSettings ├── ExcelWizard.sln └── .gitignore /ExcelWizard.Tests/Usings.cs: -------------------------------------------------------------------------------- 1 | global using FluentAssertions; 2 | global using Moq; 3 | global using Xunit; 4 | -------------------------------------------------------------------------------- /screenshots/Screenshot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/farshaddavoudi/ExcelWizard/HEAD/screenshots/Screenshot-1.png -------------------------------------------------------------------------------- /screenshots/Screenshot-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/farshaddavoudi/ExcelWizard/HEAD/screenshots/Screenshot-2.png -------------------------------------------------------------------------------- /screenshots/Screenshot-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/farshaddavoudi/ExcelWizard/HEAD/screenshots/Screenshot-3.png -------------------------------------------------------------------------------- /screenshots/Screenshot-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/farshaddavoudi/ExcelWizard/HEAD/screenshots/Screenshot-4.png -------------------------------------------------------------------------------- /screenshots/Screenshot-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/farshaddavoudi/ExcelWizard/HEAD/screenshots/Screenshot-5.png -------------------------------------------------------------------------------- /templates/ComplexExcelTemplate.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/farshaddavoudi/ExcelWizard/HEAD/templates/ComplexExcelTemplate.xlsx -------------------------------------------------------------------------------- /samples/BlazorApp/wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/farshaddavoudi/ExcelWizard/HEAD/samples/BlazorApp/wwwroot/favicon.ico -------------------------------------------------------------------------------- /samples/BlazorApp/wwwroot/icon-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/farshaddavoudi/ExcelWizard/HEAD/samples/BlazorApp/wwwroot/icon-192.png -------------------------------------------------------------------------------- /ExcelWizard/Models/EWCell/CellBuilderContracts.cs: -------------------------------------------------------------------------------- 1 | namespace ExcelWizard.Models.EWCell; 2 | 3 | public interface ICellBuilder 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /screenshots/accounts-excel-template-report.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/farshaddavoudi/ExcelWizard/HEAD/screenshots/accounts-excel-template-report.png -------------------------------------------------------------------------------- /ExcelWizard/Models/EWSheet/SheetDirection.cs: -------------------------------------------------------------------------------- 1 | namespace ExcelWizard.Models; 2 | 3 | public enum SheetDirection 4 | { 5 | LeftToRight, 6 | 7 | RightToLeft 8 | } -------------------------------------------------------------------------------- /ExcelWizard/Models/EWStyles/FontWeight.cs: -------------------------------------------------------------------------------- 1 | namespace ExcelWizard.Models.EWStyles; 2 | 3 | public enum FontWeight 4 | { 5 | Normal, 6 | 7 | Bold, 8 | 9 | Inherit 10 | } -------------------------------------------------------------------------------- /samples/ApiApp/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /samples/BlazorApp/wwwroot/css/open-iconic/font/fonts/open-iconic.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/farshaddavoudi/ExcelWizard/HEAD/samples/BlazorApp/wwwroot/css/open-iconic/font/fonts/open-iconic.eot -------------------------------------------------------------------------------- /samples/BlazorApp/wwwroot/css/open-iconic/font/fonts/open-iconic.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/farshaddavoudi/ExcelWizard/HEAD/samples/BlazorApp/wwwroot/css/open-iconic/font/fonts/open-iconic.otf -------------------------------------------------------------------------------- /samples/BlazorApp/wwwroot/css/open-iconic/font/fonts/open-iconic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/farshaddavoudi/ExcelWizard/HEAD/samples/BlazorApp/wwwroot/css/open-iconic/font/fonts/open-iconic.ttf -------------------------------------------------------------------------------- /ExcelWizard/Models/EWColumn/ColumnWidthCalculationType.cs: -------------------------------------------------------------------------------- 1 | namespace ExcelWizard.Models; 2 | 3 | public enum ColumnWidthCalculationType 4 | { 5 | ExplicitValue, 6 | 7 | AdjustToContents 8 | } -------------------------------------------------------------------------------- /samples/BlazorApp/wwwroot/css/open-iconic/font/fonts/open-iconic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/farshaddavoudi/ExcelWizard/HEAD/samples/BlazorApp/wwwroot/css/open-iconic/font/fonts/open-iconic.woff -------------------------------------------------------------------------------- /ExcelWizard.Tests/UnitTest1.cs: -------------------------------------------------------------------------------- 1 | namespace ExcelWizard.Tests 2 | { 3 | public class UnitTest1 4 | { 5 | [Fact] 6 | public void Test1() 7 | { 8 | 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /samples/ApiApp/SimorghReportModels/AccountDto.cs: -------------------------------------------------------------------------------- 1 | namespace ApiApp.SimorghReportModels; 2 | 3 | public class AccountDto 4 | { 5 | public string? Name { get; set; } 6 | 7 | public string? Code { get; set; } 8 | } -------------------------------------------------------------------------------- /samples/ApiApp/SimorghReportModels/Multiplex.cs: -------------------------------------------------------------------------------- 1 | namespace ApiApp.SimorghReportModels; 2 | 3 | public class Multiplex 4 | { 5 | public decimal Before { get; set; } 6 | 7 | public decimal After { get; set; } 8 | } -------------------------------------------------------------------------------- /samples/ApiApp/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*" 9 | } 10 | -------------------------------------------------------------------------------- /samples/ApiApp/DocExampleModels/AccountSalaryCode.cs: -------------------------------------------------------------------------------- 1 | namespace ApiApp.DocExampleModels; 2 | 3 | public class AccountSalaryCode 4 | { 5 | public string? Name { get; set; } 6 | 7 | public string? Code { get; set; } 8 | } -------------------------------------------------------------------------------- /ExcelWizard/Models/EWStyles/TextAlign.cs: -------------------------------------------------------------------------------- 1 | namespace ExcelWizard.Models.EWStyles; 2 | 3 | public enum TextAlign 4 | { 5 | Right = 0, 6 | Left = 1, 7 | Center = 2, 8 | Justify = 3, 9 | Inherit = 4 10 | } -------------------------------------------------------------------------------- /ExcelWizard/Models/EWSheet/SheetVisibility.cs: -------------------------------------------------------------------------------- 1 | namespace ExcelWizard.Models; 2 | 3 | public enum SheetVisibility 4 | { 5 | Visible, 6 | // Can UnHide 7 | Hidden, 8 | // Can not be UnHide 9 | VeryHidden 10 | } -------------------------------------------------------------------------------- /samples/ApiApp/SimorghReportModels/SummaryAccount.cs: -------------------------------------------------------------------------------- 1 | namespace ApiApp.SimorghReportModels; 2 | 3 | public class SummaryAccount 4 | { 5 | public string? AccountName { get; set; } 6 | 7 | public List Multiplex { get; set; } = new(); 8 | } -------------------------------------------------------------------------------- /ExcelWizard/Models/EWCell/CellContentType.cs: -------------------------------------------------------------------------------- 1 | namespace ExcelWizard.Models; 2 | 3 | public enum CellContentType 4 | { 5 | General, 6 | Number, 7 | Currency, 8 | GregorianDateTime, 9 | Text, 10 | Percentage, 11 | Formula 12 | } -------------------------------------------------------------------------------- /ExcelWizard/Models/EWStyles/LineStyle.cs: -------------------------------------------------------------------------------- 1 | namespace ExcelWizard.Models.EWStyles; 2 | 3 | public enum LineStyle 4 | { 5 | Thick, 6 | Thin, 7 | Dotted, 8 | Dashed, 9 | DashDot, 10 | DashDotDot, 11 | SlantDashDot, 12 | Double, 13 | None 14 | } -------------------------------------------------------------------------------- /samples/ApiApp/SimorghReportModels/VoucherStatementItem.cs: -------------------------------------------------------------------------------- 1 | namespace ApiApp.SimorghReportModels; 2 | 3 | public class VoucherStatementItem 4 | { 5 | public string? AccountCode { get; set; } 6 | 7 | public decimal Debit { get; set; } 8 | 9 | public decimal Credit { get; set; } 10 | } -------------------------------------------------------------------------------- /ExcelWizard/Models/EWGridLayout/GridLayoutExcelModel.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace ExcelWizard.Models.EWGridLayout; 4 | 5 | public class GridLayoutExcelModel 6 | { 7 | public string? GeneratedFileName { get; set; } 8 | 9 | public List Sheets { get; set; } = new(); 10 | } -------------------------------------------------------------------------------- /ExcelWizard/Models/EWStyles/TextFont.cs: -------------------------------------------------------------------------------- 1 | using System.Drawing; 2 | 3 | namespace ExcelWizard.Models.EWStyles; 4 | 5 | public class TextFont 6 | { 7 | public double? FontSize { get; set; } 8 | 9 | public bool? IsBold { get; set; } 10 | 11 | public Color? FontColor { get; set; } 12 | 13 | public string? FontName { get; set; } 14 | } -------------------------------------------------------------------------------- /samples/ApiApp/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | namespace ApiApp 2 | { 3 | public class WeatherForecast 4 | { 5 | public DateTime Date { get; set; } 6 | 7 | public int TemperatureC { get; set; } 8 | 9 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 10 | 11 | public string? Summary { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /ExcelWizard/Models/GeneratedExcelFile.cs: -------------------------------------------------------------------------------- 1 | namespace ExcelWizard.Models; 2 | 3 | public class GeneratedExcelFile 4 | { 5 | public string? FileName { get; set; } 6 | 7 | public byte[]? Content { get; set; } 8 | 9 | public string MimeType => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; 10 | 11 | public string Extension => "xlsx"; 12 | } -------------------------------------------------------------------------------- /ExcelWizard/Models/EWMerge/MergedBoundaryLocation.cs: -------------------------------------------------------------------------------- 1 | using ExcelWizard.Models.EWCell; 2 | using System.ComponentModel.DataAnnotations; 3 | 4 | namespace ExcelWizard.Models.EWMerge; 5 | 6 | public class MergedBoundaryLocation 7 | { 8 | [Required] 9 | public CellLocation? StartCellLocation { get; set; } 10 | 11 | [Required] 12 | public CellLocation? FinishCellLocation { get; set; } 13 | } -------------------------------------------------------------------------------- /samples/BlazorApp/Pages/Counter.razor: -------------------------------------------------------------------------------- 1 | @page "/counter" 2 | 3 | Counter 4 | 5 |

Counter

6 | 7 |

Current count: @currentCount

8 | 9 | 10 | 11 | @code { 12 | private int currentCount = 0; 13 | 14 | private void IncrementCount() 15 | { 16 | currentCount++; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /samples/ApiApp/DocExampleModels/AccountSharingData.cs: -------------------------------------------------------------------------------- 1 | namespace ApiApp.DocExampleModels; 2 | 3 | public class AccountSharingData 4 | { 5 | public string? AccountName { get; set; } 6 | 7 | public AccountSharingDetail AccountSharingDetail { get; set; } = new(); 8 | } 9 | 10 | public class AccountSharingDetail 11 | { 12 | public decimal BeforeSharing { get; set; } 13 | 14 | public decimal AfterSharing { get; set; } 15 | } -------------------------------------------------------------------------------- /samples/BlazorApp/_Imports.razor: -------------------------------------------------------------------------------- 1 | @using System.Net.Http 2 | @using System.Net.Http.Json 3 | @using Microsoft.AspNetCore.Components.Forms 4 | @using Microsoft.AspNetCore.Components.Routing 5 | @using Microsoft.AspNetCore.Components.Web 6 | @using Microsoft.AspNetCore.Components.Web.Virtualization 7 | @using Microsoft.AspNetCore.Components.WebAssembly.Http 8 | @using Microsoft.JSInterop 9 | @using BlazorApp 10 | @using BlazorApp.Shared 11 | -------------------------------------------------------------------------------- /samples/BlazorApp/Shared/MainLayout.razor: -------------------------------------------------------------------------------- 1 | @inherits LayoutComponentBase 2 | 3 |
4 | 7 | 8 |
9 |
10 | About 11 |
12 | 13 |
14 | @Body 15 |
16 |
17 |
18 | -------------------------------------------------------------------------------- /samples/ApiApp/SimorghReportModels/VoucherStatementResult.cs: -------------------------------------------------------------------------------- 1 | namespace ApiApp.SimorghReportModels; 2 | 3 | public class VoucherStatementResult 4 | { 5 | public string? ReportName { get; set; } 6 | 7 | public decimal FinalRemain { get; set; } 8 | 9 | public List VoucherStatementItem { get; set; } = new(); 10 | 11 | public List Accounts { get; set; } = new(); 12 | 13 | public List SummaryAccounts { get; set; } = new(); 14 | } -------------------------------------------------------------------------------- /samples/ApiApp/DocExampleModels/AccountsReportDto.cs: -------------------------------------------------------------------------------- 1 | namespace ApiApp.DocExampleModels; 2 | 3 | public class AccountsReportDto 4 | { 5 | public string? ReportName { get; set; } 6 | 7 | public List AccountDebitCreditList { get; set; } = new(); 8 | 9 | public List AccountSalaryCodes { get; set; } = new(); 10 | 11 | public List AccountSharingData { get; set; } = new(); 12 | 13 | public decimal Average { get; set; } 14 | } -------------------------------------------------------------------------------- /samples/BlazorApp/App.razor: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Not found 8 | 9 |

Sorry, there's nothing at this address.

10 |
11 |
12 |
13 | -------------------------------------------------------------------------------- /ExcelWizard/Models/EWStyles/Border.cs: -------------------------------------------------------------------------------- 1 | using System.Drawing; 2 | 3 | namespace ExcelWizard.Models.EWStyles; 4 | 5 | public class Border 6 | { 7 | #region Ctors 8 | 9 | public Border() { } 10 | 11 | public Border(LineStyle borderLineStyle, Color borderColor) 12 | { 13 | BorderLineStyle = borderLineStyle; 14 | 15 | BorderColor = borderColor; 16 | } 17 | 18 | #endregion 19 | 20 | public LineStyle BorderLineStyle { get; set; } = LineStyle.None; 21 | 22 | public Color BorderColor { get; set; } = Color.Black; 23 | } -------------------------------------------------------------------------------- /samples/BlazorApp/Program.cs: -------------------------------------------------------------------------------- 1 | using BlazorApp; 2 | using ExcelWizard; 3 | using Microsoft.AspNetCore.Components.Web; 4 | using Microsoft.AspNetCore.Components.WebAssembly.Hosting; 5 | 6 | var builder = WebAssemblyHostBuilder.CreateDefault(args); 7 | builder.RootComponents.Add("#app"); 8 | builder.RootComponents.Add("head::after"); 9 | 10 | builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); 11 | builder.Services.AddExcelWizardServices(true); 12 | 13 | await builder.Build().RunAsync(); 14 | -------------------------------------------------------------------------------- /samples/BlazorApp/wwwroot/sample-data/weather.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "date": "2018-05-06", 4 | "temperatureC": 1, 5 | "summary": "Freezing" 6 | }, 7 | { 8 | "date": "2018-05-07", 9 | "temperatureC": 14, 10 | "summary": "Bracing" 11 | }, 12 | { 13 | "date": "2018-05-08", 14 | "temperatureC": -13, 15 | "summary": "Freezing" 16 | }, 17 | { 18 | "date": "2018-05-09", 19 | "temperatureC": -16, 20 | "summary": "Balmy" 21 | }, 22 | { 23 | "date": "2018-05-10", 24 | "temperatureC": -2, 25 | "summary": "Chilly" 26 | } 27 | ] 28 | -------------------------------------------------------------------------------- /samples/ApiApp/ApiApp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /samples/BlazorApp/Shared/SurveyPrompt.razor: -------------------------------------------------------------------------------- 1 |
2 | 3 | @Title 4 | 5 | 6 | Please take our 7 | brief survey 8 | 9 | and tell us what you think. 10 |
11 | 12 | @code { 13 | // Demonstrates how a parent component can supply parameters 14 | [Parameter] 15 | public string? Title { get; set; } 16 | } 17 | -------------------------------------------------------------------------------- /samples/BlazorApp/BlazorApp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /ExcelWizard/Models/EWMerge/MergedCells.cs: -------------------------------------------------------------------------------- 1 | using ExcelWizard.Models.EWStyles; 2 | using System.Drawing; 3 | 4 | namespace ExcelWizard.Models.EWMerge; 5 | 6 | public class MergedCells : IMergeBuilder 7 | { 8 | /// 9 | /// Merged Cells Start and End Location 10 | /// 11 | public MergedBoundaryLocation MergedBoundaryLocation { get; internal set; } = new(); 12 | 13 | /// 14 | /// Set outside border of a Merged Cells (like table). Default will inherit 15 | /// 16 | public Border? OutsideBorder { get; internal set; } 17 | 18 | /// 19 | /// Set Background Color for entire Merged Cells. Default inherit 20 | /// 21 | public Color? BackgroundColor { get; internal set; } 22 | 23 | } -------------------------------------------------------------------------------- /ExcelWizard/Models/EWRow/RowStyle.cs: -------------------------------------------------------------------------------- 1 | using ExcelWizard.Models.EWStyles; 2 | using System.Drawing; 3 | 4 | namespace ExcelWizard.Models; 5 | 6 | public class RowStyle 7 | { 8 | /// 9 | /// Set Background Color for entire Row. It will override the Table Background Colors. Default inherit 10 | /// 11 | public Color? BackgroundColor { get; set; } 12 | 13 | /// 14 | /// Set Font for entire Row. It will override the Table Font. Default inherit 15 | /// 16 | public TextFont? Font { get; set; } 17 | 18 | public TextAlign? RowTextAlign { get; set; } 19 | 20 | public double? RowHeight { get; set; } 21 | 22 | public Border InsideCellsBorder { get; set; } = new(); 23 | 24 | public Border RowOutsideBorder { get; set; } = new(); 25 | } -------------------------------------------------------------------------------- /samples/BlazorApp/wwwroot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | BlazorApp 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
Loading...
16 | 17 |
18 | An unhandled error has occurred. 19 | Reload 20 | 🗙 21 |
22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /samples/ApiApp/Program.cs: -------------------------------------------------------------------------------- 1 | using ApiApp.Service; 2 | using ExcelWizard; 3 | 4 | var builder = WebApplication.CreateBuilder(args); 5 | 6 | // Add services to the container. 7 | 8 | builder.Services.AddControllers(); 9 | // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle 10 | builder.Services.AddEndpointsApiExplorer(); 11 | builder.Services.AddSwaggerGen(); 12 | 13 | builder.Services.AddExcelWizardServices(); 14 | 15 | builder.Services.AddScoped(); 16 | 17 | var app = builder.Build(); 18 | 19 | // Configure the HTTP request pipeline. 20 | if (app.Environment.IsDevelopment()) 21 | { 22 | app.UseSwagger(); 23 | app.UseSwaggerUI(); 24 | } 25 | 26 | app.UseHttpsRedirection(); 27 | 28 | app.UseAuthorization(); 29 | 30 | app.MapControllers(); 31 | 32 | app.Run(); 33 | -------------------------------------------------------------------------------- /ExcelWizard/Models/EWSheet/AllSheetsDefaultStyle.cs: -------------------------------------------------------------------------------- 1 | using ExcelWizard.Models.EWStyles; 2 | 3 | namespace ExcelWizard.Models.EWSheet 4 | { 5 | public class SheetsDefaultStyle 6 | { 7 | public SheetDirection AllSheetsDefaultDirection { get; set; } = SheetDirection.LeftToRight; 8 | 9 | public TextAlign AllSheetsDefaultTextAlign { get; set; } = TextAlign.Left; 10 | 11 | /// 12 | /// Default column width for the workbook. 13 | /// All new worksheets will use this column width. 14 | /// 15 | public double AllSheetsDefaultColumnWidth { get; set; } = 20; 16 | 17 | /// 18 | /// Default row height for the workbook. 19 | /// All new worksheets will use this row height. 20 | /// 21 | public double AllSheetsDefaultRowHeight { get; set; } = 15; 22 | } 23 | } -------------------------------------------------------------------------------- /ExcelWizard/Models/EWGridLayout/GridExcelSheet.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.ComponentModel.DataAnnotations; 3 | 4 | namespace ExcelWizard.Models.EWGridLayout; 5 | 6 | public class GridExcelSheet 7 | { 8 | /// 9 | /// Name of the bound Sheet. Is not set, get the Sheet name from SheetName property of [ExcelSheet] attribute 10 | /// 11 | public string? SheetName { get; set; } 12 | 13 | /// 14 | /// Special Data model with ExcelWizard attributes to customize the generated Excel. Should be List of items 15 | /// 16 | [Required] 17 | public object? DataList { get; set; } 18 | 19 | 20 | // Validations 21 | public void ValidateGridExcelSheetInstance() 22 | { 23 | if (DataList is not IEnumerable) 24 | throw new ValidationException("Object provided for Sheet binding should be a collection of records"); 25 | } 26 | } -------------------------------------------------------------------------------- /ExcelWizard/Models/EWCell/CellStyle.cs: -------------------------------------------------------------------------------- 1 | using ExcelWizard.Models.EWStyles; 2 | using System.Drawing; 3 | 4 | namespace ExcelWizard.Models; 5 | 6 | public class CellStyle 7 | { 8 | /// 9 | /// Set Font for the Cell. It will override the Table and Row Fonts. Default inherit 10 | /// 11 | public TextFont? Font { get; set; } 12 | 13 | /// 14 | /// Set Wordwrap for the Cell content. Default is false 15 | /// 16 | public bool Wordwrap { get; set; } 17 | 18 | public TextAlign? CellTextAlign { get; set; } 19 | 20 | /// 21 | /// Set Background Color for Cell. It will override the Table or Row or Column Background Colors. Default inherit 22 | /// 23 | public Color? BackgroundColor { get; set; } 24 | 25 | /// 26 | /// Set outside border of a table. Default is without border. 27 | /// 28 | public Border? CellBorder { get; set; } 29 | } -------------------------------------------------------------------------------- /samples/ApiApp/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:56249", 8 | "sslPort": 44384 9 | } 10 | }, 11 | "profiles": { 12 | "ApiApp": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "https://localhost:7256;http://localhost:5259", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "IIS Express": { 23 | "commandName": "IISExpress", 24 | "launchBrowser": true, 25 | "launchUrl": "swagger", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /ExcelWizard/Models/EWSheet/SheetStyle.cs: -------------------------------------------------------------------------------- 1 | using ExcelWizard.Models.EWColumn; 2 | using ExcelWizard.Models.EWStyles; 3 | using System.Collections.Generic; 4 | 5 | namespace ExcelWizard.Models; 6 | 7 | public class SheetStyle 8 | { 9 | public SheetDirection? SheetDirection { get; set; } = null; 10 | 11 | public TextAlign? SheetDefaultTextAlign { get; set; } = null; 12 | 13 | /// 14 | /// Default column width for this worksheet. 15 | /// 16 | public double? SheetDefaultColumnWidth { get; set; } = null; 17 | 18 | /// 19 | /// Default row height for this worksheet. 20 | /// 21 | public double? SheetDefaultRowHeight { get; set; } = null; 22 | 23 | public SheetVisibility Visibility { get; set; } = SheetVisibility.Visible; 24 | 25 | /// 26 | /// Sheet specific Columns style like the Column Width, TextAlign, IsHidden, IsLocked, etc 27 | /// 28 | public List ColumnsStyle { get; internal set; } = new(); 29 | } -------------------------------------------------------------------------------- /ExcelWizard/Models/ExcelModel.cs: -------------------------------------------------------------------------------- 1 | using ExcelWizard.Models.EWSheet; 2 | using System.Collections.Generic; 3 | 4 | namespace ExcelWizard.Models; 5 | 6 | public class ExcelModel : IExcelBuilder 7 | { 8 | /// 9 | /// Excel file name without .Xlsx extension. Excel file will be generated with this file name 10 | /// 11 | public string? GeneratedFileName { get; internal set; } 12 | 13 | /// 14 | /// All Sheets shared default styles including default ColumnWidth, default RowHeight and sheets language Direction 15 | /// 16 | public SheetsDefaultStyle SheetsDefaultStyle { get; internal set; } = new(); 17 | 18 | /// 19 | /// Set the default IsLocked value for all Sheets. Default is false 20 | /// 21 | public bool AreSheetsLockedByDefault { get; internal set; } = false; 22 | 23 | /// 24 | /// Excel Sheets data and configurations 25 | /// 26 | public List Sheets { get; internal set; } = new(); 27 | } -------------------------------------------------------------------------------- /ExcelWizard/Models/EWExcel/SheetBinding.cs: -------------------------------------------------------------------------------- 1 | namespace ExcelWizard.Models.EWExcel; 2 | 3 | public class BindingSheet 4 | { 5 | /// List of data list. e.g. object list of Persons, Phones, Universities, etc which each will be mapped to a Sheet 6 | /// Name of the bound Sheet. If not set, get the Sheet name from SheetName property of [ExcelSheet] attribute 7 | public BindingSheet(object bindingListModel, string? sheetName = null) 8 | { 9 | BindingListModel = bindingListModel; 10 | SheetName = sheetName; 11 | } 12 | 13 | /// 14 | /// List of data list. e.g. object list of Persons, Phones, Universities, etc which each will be mapped to a Sheet 15 | /// 16 | public object? BindingListModel { get; set; } 17 | 18 | /// 19 | /// Name of the bound Sheet. If not set, get the Sheet name from SheetName property of [ExcelSheet] attribute 20 | /// 21 | public string? SheetName { get; set; } 22 | } -------------------------------------------------------------------------------- /samples/BlazorApp/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:62899", 7 | "sslPort": 44394 8 | } 9 | }, 10 | "profiles": { 11 | "BlazorApp": { 12 | "commandName": "Project", 13 | "dotnetRunMessages": true, 14 | "launchBrowser": true, 15 | "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", 16 | "applicationUrl": "https://localhost:7287;http://localhost:5287", 17 | "environmentVariables": { 18 | "ASPNETCORE_ENVIRONMENT": "Development" 19 | } 20 | }, 21 | "IIS Express": { 22 | "commandName": "IISExpress", 23 | "launchBrowser": true, 24 | "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", 25 | "environmentVariables": { 26 | "ASPNETCORE_ENVIRONMENT": "Development" 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ExcelWizard/Models/EWTable/TableStyle.cs: -------------------------------------------------------------------------------- 1 | using ExcelWizard.Models.EWStyles; 2 | using System.Drawing; 3 | 4 | namespace ExcelWizard.Models; 5 | 6 | public class TableStyle 7 | { 8 | /// 9 | /// Set Background Color for entire Table. It will override the Sheet Background Color. Default inherit 10 | /// 11 | public Color? BackgroundColor { get; set; } 12 | 13 | /// 14 | /// Set the Font props (font-family, size, color, etc) for the entire table 15 | /// 16 | public TextFont? Font { get; set; } 17 | 18 | public TextAlign? TableTextAlign { get; set; } 19 | 20 | /// 21 | /// Set outside border of a table. Default is thin border. 22 | /// 23 | public Border TableOutsideBorder { get; set; } = new(LineStyle.Thin, Color.LightGray); 24 | 25 | /// 26 | /// Set inside borders of table Cells. It do not effect the table Outside borders! Default is Thin border (Like Excel normal cells) 27 | /// 28 | public Border InsideCellsBorder { get; set; } = new(LineStyle.Thin, Color.LightGray); 29 | } -------------------------------------------------------------------------------- /samples/BlazorApp/AppExcelReportModel.cs: -------------------------------------------------------------------------------- 1 | using ExcelWizard.Models; 2 | using ExcelWizard.Models.EWGridLayout; 3 | using ExcelWizard.Models.EWStyles; 4 | using System.Drawing; 5 | 6 | namespace BlazorApp; 7 | 8 | [ExcelSheet(SheetName = "MyReport", DefaultTextAlign = TextAlign.Center, HeaderBackgroundColor = KnownColor.LightBlue, HeaderHeight = 40, 9 | BorderType = LineStyle.DashDotDot, DataBackgroundColor = KnownColor.Bisque, DataRowHeight = 25, IsSheetLocked = true, 10 | SheetDirection = SheetDirection.RightToLeft, FontColor = KnownColor.Red)] 11 | public class AppExcelReportModel 12 | { 13 | [ExcelSheetColumn(HeaderName = "شناسه", HeaderTextAlign = TextAlign.Right, DataTextAlign = TextAlign.Right, FontColor = KnownColor.Blue)] 14 | public int Id { get; set; } 15 | 16 | [ExcelSheetColumn(Ignore = true, HeaderName = "Name", HeaderTextAlign = TextAlign.Left, FontWeight = FontWeight.Bold)] 17 | public string? FullName { get; set; } 18 | 19 | [ExcelSheetColumn(HeaderName = "شماره پرسنلی", HeaderTextAlign = TextAlign.Left, ColumnWidth = 50, FontSize = 15)] 20 | public string? PersonnelCode { get; set; } 21 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Farshad Davoudi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /samples/ApiApp/Service/ISimorghExcelBuilderService.cs: -------------------------------------------------------------------------------- 1 | using ApiApp.SimorghReportModels; 2 | using ExcelWizard.Models; 3 | 4 | namespace ApiApp.Service; 5 | 6 | public interface ISimorghExcelBuilderService 7 | { 8 | /// 9 | /// Generate Simorgh Co. VoucherStatement Excel Report with Custom Template from VoucherStatementResult model. 10 | /// With this Service, We Can Generate The Customized Excel everywhere in the project by just calling this method 11 | /// 12 | /// Returns ByteArray of Generated Excel file 13 | public GeneratedExcelFile GenerateVoucherStatementExcelReport(VoucherStatementResult voucherStatement); 14 | 15 | /// 16 | /// Generate Simorgh Co. VoucherStatement Excel Report with Custom Template from VoucherStatementResult model. 17 | /// With this Service, We Can Generate The Customized Excel everywhere in the project by just calling this method 18 | /// 19 | /// Returns Full Path which the Generated Excel Saved there 20 | public string GenerateVoucherStatementExcelReport(VoucherStatementResult voucherStatement, string savePath); 21 | } -------------------------------------------------------------------------------- /samples/ApiApp/User.cs: -------------------------------------------------------------------------------- 1 | using ExcelWizard.Models; 2 | using ExcelWizard.Models.EWGridLayout; 3 | using ExcelWizard.Models.EWStyles; 4 | using System.Drawing; 5 | 6 | namespace ApiApp; 7 | 8 | [ExcelSheet(SheetName = "MyUsers", DefaultTextAlign = TextAlign.Center, HeaderBackgroundColor = KnownColor.LightBlue, HeaderHeight = 40, 9 | BorderType = LineStyle.DashDotDot, DataBackgroundColor = KnownColor.Bisque, DataRowHeight = 25, IsSheetLocked = true, 10 | SheetDirection = SheetDirection.RightToLeft, FontColor = KnownColor.Red, BorderColor = KnownColor.Black)] 11 | public class User 12 | { 13 | [ExcelSheetColumn(HeaderName = "UserId", HeaderTextAlign = TextAlign.Right, DataTextAlign = TextAlign.Right, FontColor = KnownColor.Blue)] 14 | public int Id { get; set; } 15 | 16 | [ExcelSheetColumn(HeaderName = "Name", HeaderTextAlign = TextAlign.Left, FontWeight = FontWeight.Bold)] 17 | public string? FullName { get; set; } 18 | 19 | [ExcelSheetColumn(HeaderName = "Personnel No", HeaderTextAlign = TextAlign.Left, ColumnWidth = 50, FontSize = 15)] 20 | public string? PersonnelCode { get; set; } 21 | 22 | public string? Nationality { get; set; } 23 | } -------------------------------------------------------------------------------- /samples/ApiApp/Controllers/WeatherForecastController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | 3 | namespace ApiApp.Controllers 4 | { 5 | [ApiController] 6 | [Route("[controller]")] 7 | public class WeatherForecastController : ControllerBase 8 | { 9 | private static readonly string[] Summaries = new[] 10 | { 11 | "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" 12 | }; 13 | 14 | private readonly ILogger _logger; 15 | 16 | public WeatherForecastController(ILogger logger) 17 | { 18 | _logger = logger; 19 | } 20 | 21 | [HttpGet(Name = "GetWeatherForecast")] 22 | public IEnumerable Get() 23 | { 24 | return Enumerable.Range(1, 5).Select(index => new WeatherForecast 25 | { 26 | Date = DateTime.Now.AddDays(index), 27 | TemperatureC = Random.Shared.Next(-20, 55), 28 | Summary = Summaries[Random.Shared.Next(Summaries.Length)] 29 | }) 30 | .ToArray(); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /samples/BlazorApp/wwwroot/css/open-iconic/ICON-LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Waybury 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /ExcelWizard/Models/ProtectionLevel.cs: -------------------------------------------------------------------------------- 1 | namespace ExcelWizard.Models; 2 | 3 | public class ProtectionLevel 4 | { 5 | public string? Password { get; set; } 6 | 7 | public bool SelectLockedCells { get; set; } = true; 8 | 9 | public bool SelectUnlockedCells { get; set; } = true; 10 | 11 | public bool FormatCells { get; set; } = true; 12 | 13 | public bool FormatColumns { get; set; } = true; 14 | 15 | public bool FormatRows { get; set; } = true; 16 | 17 | public bool InsertColumns { get; set; } = true; 18 | 19 | public bool InsertRows { get; set; } = true; 20 | 21 | public bool InsertHyperLinks { get; set; } = true; 22 | 23 | public bool DeleteColumns { get; set; } = true; 24 | 25 | public bool DeleteRows { get; set; } = true; 26 | 27 | public bool Sort { get; set; } = true; 28 | 29 | public bool UseAutoFilter { get; set; } = true; 30 | 31 | public bool UsePivotTableReports { get; set; } = true; 32 | 33 | public bool EditObjects { get; set; } = true; 34 | 35 | public bool EditScenarios { get; set; } = true; 36 | 37 | public bool HardProtect { get; set; } = false; // Will disable all the elements and hardly protect the Sheet 38 | } -------------------------------------------------------------------------------- /ExcelWizard/Models/EWCell/CellLocation.cs: -------------------------------------------------------------------------------- 1 | namespace ExcelWizard.Models.EWCell; 2 | 3 | public class CellLocation 4 | { 5 | /// Cell Column Letter 6 | /// Cell Row Number 7 | public CellLocation(string columnLetter, int rowNumber) 8 | { 9 | ColumnNumber = columnLetter.GetCellColumnNumberByCellColumnLetter(); 10 | RowNumber = rowNumber; 11 | } 12 | 13 | /// Cell Column Number 14 | /// Cell Row Number 15 | public CellLocation(int columnNumber, int rowNumber) 16 | { 17 | ColumnNumber = columnNumber; 18 | RowNumber = rowNumber; 19 | } 20 | 21 | /// 22 | /// X Location 23 | /// 24 | public int ColumnNumber { get; } 25 | 26 | /// 27 | /// Y Location 28 | /// 29 | public int RowNumber { get; } 30 | 31 | /// 32 | /// Get Cell Location Display Name, e.g. "A2" or "B13" 33 | /// 34 | /// 35 | public string GetCellLocationDisplayName() 36 | { 37 | return $"{ColumnNumber.GetCellColumnLetterByCellColumnNumber()}{RowNumber}"; 38 | } 39 | } -------------------------------------------------------------------------------- /samples/ApiApp/DocExampleModels/AccountDebitCredit.cs: -------------------------------------------------------------------------------- 1 | using ExcelWizard.Models; 2 | using ExcelWizard.Models.EWStyles; 3 | using ExcelWizard.Models.EWTable; 4 | using System.Drawing; 5 | 6 | namespace ApiApp.DocExampleModels; 7 | 8 | [ExcelTable(HeaderBackgroundColor = KnownColor.LightGray, 9 | HeaderFontColor = KnownColor.Red, 10 | HeaderFontWeight = FontWeight.Normal, 11 | //HeaderOccupyingRowsNo = 3, 12 | InsideCellsBorderStyle = LineStyle.Thick, 13 | InsideCellsBorderColor = KnownColor.Black, 14 | OutsideBorderColor = KnownColor.Black, 15 | OutsideBorderStyle = LineStyle.Thick, 16 | FontColor = KnownColor.Blue, 17 | HasHeader = true, 18 | FontSize = 11, 19 | TextAlign = TextAlign.Center)] 20 | public class AccountDebitCredit 21 | { 22 | [ExcelTableColumn(HeaderName = "Account Code", FontColor = KnownColor.DarkOrange, DataTextAlign = TextAlign.Right, 23 | HeaderTextAlign = TextAlign.Left, FontSize = 13, FontWeight = FontWeight.Bold)] 24 | public string? AccountCode { get; set; } 25 | 26 | [ExcelTableColumn(DataContentType = CellContentType.Currency)] 27 | public decimal Debit { get; set; } 28 | 29 | [ExcelTableColumn(DataContentType = CellContentType.Currency, Ignore = false)] 30 | public decimal Credit { get; set; } 31 | } 32 | 33 | 34 | -------------------------------------------------------------------------------- /samples/BlazorApp/Pages/Index.razor: -------------------------------------------------------------------------------- 1 | @page "/" 2 | @using ExcelWizard.Service 3 | @using BlazorDownloadFile 4 | @using ExcelWizard.Models 5 | @using ExcelWizard.Models.EWExcel 6 | 7 | Index 8 | 9 |

Hello, world!

10 | 11 | Welcome to your new app. 12 | 13 | 14 | 15 | 16 | 17 | 18 | @code { 19 | 20 | [Inject] private IExcelWizardService ExcelWizardService { get; set; } = default!; 21 | 22 | private Task GenerateExcelReport() 23 | { 24 | var fetchDataFromApi = new List 25 | { 26 | new() { Id = 1, FullName = "کریس رونالدو ", PersonnelCode = "980923" }, 27 | new() { Id = 2, FullName = "روبرتو کارلس", PersonnelCode = "991126" }, 28 | new() { Id = 3, FullName = "مارسل دسایی", PersonnelCode = "941126" } 29 | }; 30 | 31 | var excelBuilder = ExcelBuilder 32 | .SetGeneratedFileName("my-custom-report") 33 | .CreateGridLayoutExcel() 34 | .WithOneSheetUsingModelBinding(fetchDataFromApi) 35 | .Build(); 36 | 37 | return ExcelWizardService.GenerateAndDownloadExcelInBlazor(excelBuilder); 38 | } 39 | } -------------------------------------------------------------------------------- /ExcelWizard/Models/EWColumn/ColumnStyle.cs: -------------------------------------------------------------------------------- 1 | using ExcelWizard.Models.EWStyles; 2 | 3 | namespace ExcelWizard.Models.EWColumn; 4 | 5 | public class ColumnStyle 6 | { 7 | /// Column Letter 8 | public ColumnStyle(string columnLetter) 9 | { 10 | ColumnNumber = columnLetter.GetCellColumnNumberByCellColumnLetter(); 11 | } 12 | 13 | /// Column Number 14 | public ColumnStyle(int columnNumber) 15 | { 16 | ColumnNumber = columnNumber; 17 | } 18 | 19 | public int ColumnNumber { get; set; } 20 | 21 | /// 22 | /// If not specified, default would be considered 23 | /// 24 | public ColumnWidth? ColumnWidth { get; set; } = null; 25 | 26 | public TextAlign ColumnTextAlign { get; set; } = TextAlign.Right; //Default RTL direction 27 | 28 | public bool IsColumnHidden { get; set; } = false; 29 | 30 | // TODO: Add MergedCells for Columns property 31 | 32 | public bool AutoFit { get; set; } = false; //TODO: has same concept with Width class (duplicate) 33 | 34 | /// 35 | /// Default is null, and it gets Sheet "IsLocked" property value in this case, but if specified, it will override it 36 | /// 37 | public bool? IsColumnLocked { get; set; } = null; 38 | } -------------------------------------------------------------------------------- /samples/BlazorApp/Shared/NavMenu.razor.css: -------------------------------------------------------------------------------- 1 | .navbar-toggler { 2 | background-color: rgba(255, 255, 255, 0.1); 3 | } 4 | 5 | .top-row { 6 | height: 3.5rem; 7 | background-color: rgba(0,0,0,0.4); 8 | } 9 | 10 | .navbar-brand { 11 | font-size: 1.1rem; 12 | } 13 | 14 | .oi { 15 | width: 2rem; 16 | font-size: 1.1rem; 17 | vertical-align: text-top; 18 | top: -2px; 19 | } 20 | 21 | .nav-item { 22 | font-size: 0.9rem; 23 | padding-bottom: 0.5rem; 24 | } 25 | 26 | .nav-item:first-of-type { 27 | padding-top: 1rem; 28 | } 29 | 30 | .nav-item:last-of-type { 31 | padding-bottom: 1rem; 32 | } 33 | 34 | .nav-item ::deep a { 35 | color: #d7d7d7; 36 | border-radius: 4px; 37 | height: 3rem; 38 | display: flex; 39 | align-items: center; 40 | line-height: 3rem; 41 | } 42 | 43 | .nav-item ::deep a.active { 44 | background-color: rgba(255,255,255,0.25); 45 | color: white; 46 | } 47 | 48 | .nav-item ::deep a:hover { 49 | background-color: rgba(255,255,255,0.1); 50 | color: white; 51 | } 52 | 53 | @media (min-width: 641px) { 54 | .navbar-toggler { 55 | display: none; 56 | } 57 | 58 | .collapse { 59 | /* Never collapse the sidebar for wide screens */ 60 | display: block; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /ExcelWizard.sln.DotSettings: -------------------------------------------------------------------------------- 1 | 2 | True 3 | True 4 | True 5 | True 6 | True 7 | True 8 | True 9 | True 10 | True -------------------------------------------------------------------------------- /ExcelWizard.Tests/ExcelWizard.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | false 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | runtime; build; native; contentfiles; analyzers; buildtransitive 18 | all 19 | 20 | 21 | runtime; build; native; contentfiles; analyzers; buildtransitive 22 | all 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /ExcelWizard/Service/IExcelWizardService.cs: -------------------------------------------------------------------------------- 1 | using BlazorDownloadFile; 2 | using ExcelWizard.Models; 3 | using System.Threading.Tasks; 4 | 5 | namespace ExcelWizard.Service; 6 | 7 | public interface IExcelWizardService 8 | { 9 | /// 10 | /// Generate Excel file by providing equivalent CSharp model 11 | /// 12 | /// ExcelBuilder with Build() method at the end 13 | /// Byte array of generated Excel saved in memory. 14 | GeneratedExcelFile GenerateExcel(IExcelBuilder excelBuilder); 15 | 16 | /// 17 | /// Generate Excel file by providing equivalent CSharp model 18 | /// 19 | /// ExcelBuilder with Build() method at the end 20 | /// The url saved 21 | /// Save generated Excel in a path in your device 22 | string GenerateExcel(IExcelBuilder excelBuilder, string savePath); 23 | 24 | /// 25 | /// [Blazor only] Generate and Download instantly from Browser the generated file by providing equivalent CSharp model 26 | /// 27 | /// ExcelBuilder with Build() method at the end 28 | /// Instantly download from Browser 29 | Task GenerateAndDownloadExcelInBlazor(IExcelBuilder excelBuilder); 30 | } -------------------------------------------------------------------------------- /samples/BlazorApp/Shared/NavMenu.razor: -------------------------------------------------------------------------------- 1 | 9 | 10 |
11 | 28 |
29 | 30 | @code { 31 | private bool collapseNavMenu = true; 32 | 33 | private string? NavMenuCssClass => collapseNavMenu ? "collapse" : null; 34 | 35 | private void ToggleNavMenu() 36 | { 37 | collapseNavMenu = !collapseNavMenu; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /ExcelWizard/Models/EWMerge/MergeBuilderContracts.cs: -------------------------------------------------------------------------------- 1 | using ExcelWizard.Models.EWStyles; 2 | using System.Drawing; 3 | 4 | namespace ExcelWizard.Models.EWMerge; 5 | 6 | public interface IMergeBuilder 7 | { 8 | 9 | } 10 | 11 | public interface IExpectMergingFinishPointMergeBuilder 12 | { 13 | /// 14 | /// Set merging finish location cell 15 | /// 16 | /// Finish location column letter or number, e.g. "A" or 1 17 | /// Finish location row number, e.g. 1 18 | IExpectStylesOrBuildMergeBuilder SetMergingFinishPoint(dynamic columnLetterOrNumber, int rowNumber); 19 | } 20 | 21 | public interface IExpectStylesOrBuildMergeBuilder 22 | { 23 | /// 24 | /// Set Background Color for entire Merged Cells. Default inherit 25 | /// 26 | /// Merge area background color 27 | /// 28 | IExpectStylesOrBuildMergeBuilder SetMergingAreaBackgroundColor(Color backgroundColor); 29 | 30 | /// 31 | /// Set outside border of a Merged Cells (like table). Default will inherit 32 | /// 33 | /// 34 | /// 35 | IExpectStylesOrBuildMergeBuilder SetMergingOutsideBorder(LineStyle borderLineStyle = LineStyle.Thin, Color borderColor = new()); 36 | 37 | IMergeBuilder Build(); 38 | } -------------------------------------------------------------------------------- /ExcelWizard/Models/EWCell/Cell.cs: -------------------------------------------------------------------------------- 1 | namespace ExcelWizard.Models.EWCell; 2 | 3 | public class Cell : ICellBuilder 4 | { 5 | /// 6 | /// An arbitrary property to distinguish the Cells. For example can be the db Id (which are not suppose to be shown in the Excel) 7 | /// 8 | public string? CellIdentifier { get; internal set; } 9 | 10 | /// 11 | /// Cell Value that are displayed 12 | /// 13 | public object? CellValue { get; internal set; } 14 | 15 | /// 16 | /// Cell Location. Row is Number only and Column can be both Letter (e.g. "B") or No (e.g. 2) 17 | /// 18 | #pragma warning disable CS8618 19 | public CellLocation CellLocation { get; internal set; } 20 | #pragma warning restore CS8618 21 | 22 | /// 23 | /// Set Cell Styles including Font, Wrap behaviour, Align and etc 24 | /// 25 | public CellStyle CellStyle { get; internal set; } = new(); 26 | 27 | public CellContentType CellContentType { get; internal set; } = CellContentType.General; 28 | 29 | /// 30 | /// Show / Hide Cell Content in Generated Excel 31 | /// 32 | public bool IsCellVisible { get; internal set; } = true; 33 | 34 | /// 35 | /// Will override the IsSheetLocked property of Sheet model if set to a value. Default will inherit 36 | /// 37 | public bool? IsCellLocked { get; internal set; } = null; 38 | } -------------------------------------------------------------------------------- /ExcelWizard/Models/EWColumn/ColumnWidth.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.ComponentModel.DataAnnotations; 3 | 4 | namespace ExcelWizard.Models; 5 | 6 | public class ColumnWidth : IValidatableObject 7 | { 8 | public ColumnWidthCalculationType WidthCalculationType { get; set; } = ColumnWidthCalculationType.AdjustToContents; 9 | 10 | /// 11 | /// Width value of the Column. In case of ColumnWidthCalculationType.AdjustToContents it should be left null 12 | /// 13 | public double? Width { get; set; } 14 | 15 | // Validations 16 | public IEnumerable Validate(ValidationContext validationContext) 17 | { 18 | if (WidthCalculationType == ColumnWidthCalculationType.AdjustToContents) 19 | { 20 | if (Width is not null) 21 | { 22 | yield return new ValidationResult( 23 | "Column with AdjustToContent Width calculation type cannot have explicit value", 24 | new List { nameof(Width) }); 25 | } 26 | } 27 | 28 | if (WidthCalculationType == ColumnWidthCalculationType.ExplicitValue) 29 | { 30 | if (Width is null) 31 | { 32 | yield return new ValidationResult( 33 | "Column width value should be specified when CalculationType is set to explicit value", 34 | new List { nameof(Width) } 35 | ); 36 | } 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /samples/BlazorApp/Pages/FetchData.razor: -------------------------------------------------------------------------------- 1 | @page "/fetchdata" 2 | @inject HttpClient Http 3 | 4 | Weather forecast 5 | 6 |

Weather forecast

7 | 8 |

This component demonstrates fetching data from the server.

9 | 10 | @if (forecasts == null) 11 | { 12 |

Loading...

13 | } 14 | else 15 | { 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | @foreach (var forecast in forecasts) 27 | { 28 | 29 | 30 | 31 | 32 | 33 | 34 | } 35 | 36 |
DateTemp. (C)Temp. (F)Summary
@forecast.Date.ToShortDateString()@forecast.TemperatureC@forecast.TemperatureF@forecast.Summary
37 | } 38 | 39 | @code { 40 | private WeatherForecast[]? forecasts; 41 | 42 | protected override async Task OnInitializedAsync() 43 | { 44 | forecasts = await Http.GetFromJsonAsync("sample-data/weather.json"); 45 | } 46 | 47 | public class WeatherForecast 48 | { 49 | public DateTime Date { get; set; } 50 | 51 | public int TemperatureC { get; set; } 52 | 53 | public string? Summary { get; set; } 54 | 55 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /samples/BlazorApp/Shared/MainLayout.razor.css: -------------------------------------------------------------------------------- 1 | .page { 2 | position: relative; 3 | display: flex; 4 | flex-direction: column; 5 | } 6 | 7 | main { 8 | flex: 1; 9 | } 10 | 11 | .sidebar { 12 | background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%); 13 | } 14 | 15 | .top-row { 16 | background-color: #f7f7f7; 17 | border-bottom: 1px solid #d6d5d5; 18 | justify-content: flex-end; 19 | height: 3.5rem; 20 | display: flex; 21 | align-items: center; 22 | } 23 | 24 | .top-row ::deep a, .top-row ::deep .btn-link { 25 | white-space: nowrap; 26 | margin-left: 1.5rem; 27 | text-decoration: none; 28 | } 29 | 30 | .top-row ::deep a:hover, .top-row ::deep .btn-link:hover { 31 | text-decoration: underline; 32 | } 33 | 34 | .top-row ::deep a:first-child { 35 | overflow: hidden; 36 | text-overflow: ellipsis; 37 | } 38 | 39 | @media (max-width: 640.98px) { 40 | .top-row:not(.auth) { 41 | display: none; 42 | } 43 | 44 | .top-row.auth { 45 | justify-content: space-between; 46 | } 47 | 48 | .top-row ::deep a, .top-row ::deep .btn-link { 49 | margin-left: 0; 50 | } 51 | } 52 | 53 | @media (min-width: 641px) { 54 | .page { 55 | flex-direction: row; 56 | } 57 | 58 | .sidebar { 59 | width: 250px; 60 | height: 100vh; 61 | position: sticky; 62 | top: 0; 63 | } 64 | 65 | .top-row { 66 | position: sticky; 67 | top: 0; 68 | z-index: 1; 69 | } 70 | 71 | .top-row.auth ::deep a:first-child { 72 | flex: 1; 73 | text-align: right; 74 | width: 0; 75 | } 76 | 77 | .top-row, article { 78 | padding-left: 2rem !important; 79 | padding-right: 1.5rem !important; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /ExcelWizard/ExcelWizard.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.1 5 | 3.0.9 6 | latest 7 | $(NoWarn);NU1701;1702;1591;NU1602;CS8609;CS8610;CS8619;CS8632 8 | enable 9 | 10 | 11 | 12 | Farshad Davoudi 13 | ExcelWizard 14 | 15 | Easily generate Excel file based on your model in a very simple and straightforward way. In addition, make the generated Excel file directly downloadable from Browser without any hassle in case of using Blazor application. Excel easy import is also included. 16 | 17 | true 18 | 19 | README.md 20 | MIT License 21 | MIT 22 | https://github.com/farshaddavoudi/ExcelWizard 23 | 24 | 25 | 26 | portable 27 | true 28 | 29 | 30 | 31 | $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb;.xml 32 | True 33 | portable 34 | true 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /ExcelWizard/Models/EWTable/ExcelTableColumnAttribute.cs: -------------------------------------------------------------------------------- 1 | using ExcelWizard.Models.EWStyles; 2 | using System; 3 | using System.Drawing; 4 | 5 | namespace ExcelWizard.Models.EWTable; 6 | 7 | /// 8 | /// Configure the Table Columns 9 | /// 10 | [AttributeUsage(AttributeTargets.Property)] 11 | public class ExcelTableColumnAttribute : Attribute 12 | { 13 | /// 14 | /// Ignore the Column from being shown in exported Excel. It also will not occupy any location 15 | /// 16 | public bool Ignore { get; set; } 17 | 18 | /// 19 | /// Column Header Name. Default is the property name. 20 | /// It will be ignored if Table HasHeader property is set to false 21 | /// 22 | public string? HeaderName { get; set; } 23 | 24 | /// 25 | /// Header Text Align. Will override default oneWill be ignored if Table HasHeader property is set to false 26 | /// 27 | public TextAlign HeaderTextAlign { get; set; } = TextAlign.Inherit; 28 | 29 | /// 30 | /// Data Cells Text Align for the Column. Will override the default one 31 | /// 32 | public TextAlign DataTextAlign { get; set; } = TextAlign.Inherit; 33 | 34 | /// 35 | /// Table column data type. Default is Text type 36 | /// 37 | public CellContentType DataContentType { get; set; } = CellContentType.Text; 38 | 39 | /// 40 | /// Column FontFamily Name 41 | /// 42 | public string? FontName { get; set; } 43 | 44 | /// 45 | /// Column FontColor. Transparent color means reverting back to Table FontColor 46 | /// 47 | public KnownColor FontColor { get; set; } = KnownColor.Transparent; 48 | 49 | /// 50 | /// Column FontSize. If 0 it means default FontSize 51 | /// 52 | public int FontSize { get; set; } 53 | 54 | /// 55 | /// Is Column Font Bold. Inherit means revert back to Table Font Weight 56 | /// 57 | public FontWeight FontWeight { get; set; } = FontWeight.Inherit; 58 | } -------------------------------------------------------------------------------- /ExcelWizard/Models/EWGridLayout/ExcelSheetColumnAttribute.cs: -------------------------------------------------------------------------------- 1 | using ExcelWizard.Models.EWStyles; 2 | using System; 3 | using System.Drawing; 4 | 5 | namespace ExcelWizard.Models.EWGridLayout; 6 | 7 | /// 8 | /// Configure the Excel Column mapped to this property 9 | /// 10 | [AttributeUsage(AttributeTargets.Property)] 11 | public class ExcelSheetColumnAttribute : Attribute 12 | { 13 | /// 14 | /// Ignore the Column from being shown in exported Excel 15 | /// 16 | public bool Ignore { get; set; } 17 | 18 | /// 19 | /// Column Header Name. Default is the property name 20 | /// 21 | public string? HeaderName { get; set; } 22 | 23 | /// 24 | /// Header Text Align. Will override default one 25 | /// 26 | public TextAlign HeaderTextAlign { get; set; } = TextAlign.Inherit; 27 | 28 | /// 29 | /// Data Cells Text Align for the Column. Will override the default one 30 | /// 31 | public TextAlign DataTextAlign { get; set; } = TextAlign.Inherit; 32 | 33 | /// 34 | /// Excel Data Type. Default is Text type 35 | /// 36 | public CellContentType ExcelDataContentType { get; set; } = CellContentType.Text; 37 | 38 | /// 39 | /// Column Width. If 0 it means Width automatically set to AdjustToContents 40 | /// 41 | public int ColumnWidth { get; set; } 42 | 43 | /// 44 | /// Column FontFamily Name 45 | /// 46 | public string? FontName { get; set; } 47 | 48 | /// 49 | /// Column FontColor. Transparent color means reverting back to Sheet FontColor 50 | /// 51 | public KnownColor FontColor { get; set; } = KnownColor.Transparent; 52 | 53 | /// 54 | /// Column FontSize. If 0 it means default FontSize 55 | /// 56 | public int FontSize { get; set; } 57 | 58 | /// 59 | /// Is Column Font Bold. Inherit means revert back to Sheet Font Weight (IsBold property) 60 | /// 61 | public FontWeight FontWeight { get; set; } = FontWeight.Inherit; 62 | } -------------------------------------------------------------------------------- /ExcelWizard/Models/EWSheet/Sheet.cs: -------------------------------------------------------------------------------- 1 | using ExcelWizard.Models.EWCell; 2 | using ExcelWizard.Models.EWMerge; 3 | using ExcelWizard.Models.EWRow; 4 | using ExcelWizard.Models.EWTable; 5 | using System.Collections.Generic; 6 | 7 | namespace ExcelWizard.Models.EWSheet; 8 | 9 | public class Sheet : ISheetBuilder 10 | { 11 | /// 12 | /// Sheet name 13 | /// 14 | public string? SheetName { get; internal set; } 15 | 16 | /// 17 | /// Insert one or more Table(s) data into the Sheet. 18 | /// Each Table is consist of some Rows and Cells with more style options to configure easily 19 | /// 20 | public List SheetTables { get; internal set; } = new(); 21 | 22 | /// 23 | /// Insert one or more Row(s) records into the Sheet. 24 | /// Each Row is consist of some Cells with more style options to configure easily 25 | /// 26 | public List SheetRows { get; internal set; } = new(); 27 | 28 | /// 29 | /// Insert one or more Cell(s) items directly into the Sheet. 30 | /// All data can be inserted with this property, but using Tables and Rows add more options to configure style and functionality of generated Sheet. 31 | /// 32 | public List SheetCells { get; internal set; } = new(); 33 | 34 | /// 35 | /// Sheet style options like Direction, TextAlign, ColumnsDefaultWith, RowsDefaultHeight and etc. Also Columns style can be configured here 36 | /// 37 | public SheetStyle SheetStyle { get; internal set; } = new(); 38 | 39 | /// 40 | /// Merged Cells in the Sheet. If it is possible to write Merges on the Table or Row models, manage to do that instead of here 41 | /// 42 | public List MergedCellsList { get; internal set; } = new(); 43 | 44 | /// 45 | /// Will override the ExcelBuilder AreSheetsLockedByDefault value. Default will inherit 46 | /// 47 | public bool? IsSheetLocked { get; internal set; } 48 | 49 | /// 50 | /// All features are accessible. No limitation will apply 51 | /// 52 | public bool IsSheetProtected { get; internal set; } 53 | 54 | /// 55 | /// Set Sheet protection level 56 | /// 57 | public ProtectionLevel SheetProtectionLevel { get; internal set; } = new(); 58 | } -------------------------------------------------------------------------------- /ExcelWizard/Models/EWMerge/MergeBuilder.cs: -------------------------------------------------------------------------------- 1 | using ExcelWizard.Models.EWCell; 2 | using ExcelWizard.Models.EWStyles; 3 | using System; 4 | using System.Drawing; 5 | 6 | namespace ExcelWizard.Models.EWMerge; 7 | 8 | public class MergeBuilder : IExpectMergingFinishPointMergeBuilder, IExpectStylesOrBuildMergeBuilder 9 | { 10 | private MergeBuilder() { } 11 | 12 | private MergedCells MergedCells { get; set; } = new(); 13 | private bool CanBuild { get; set; } 14 | 15 | /// 16 | /// Set merging start location cell 17 | /// 18 | /// Start location column letter or number, e.g. "A" or 1 19 | /// Start location row number, e.g. 1 20 | public static IExpectMergingFinishPointMergeBuilder SetMergingStartPoint(dynamic columnLetterOrNumber, int rowNumber) 21 | { 22 | return new MergeBuilder 23 | { 24 | MergedCells = new MergedCells 25 | { 26 | MergedBoundaryLocation = new MergedBoundaryLocation 27 | { 28 | StartCellLocation = new CellLocation(columnLetterOrNumber, rowNumber) 29 | } 30 | } 31 | }; 32 | } 33 | 34 | public IExpectStylesOrBuildMergeBuilder SetMergingFinishPoint(dynamic columnLetterOrNumber, int rowNumber) 35 | { 36 | CanBuild = true; 37 | 38 | MergedCells.MergedBoundaryLocation.FinishCellLocation = new CellLocation(columnLetterOrNumber, rowNumber); 39 | 40 | return this; 41 | } 42 | 43 | public IExpectStylesOrBuildMergeBuilder SetMergingAreaBackgroundColor(Color backgroundColor) 44 | { 45 | MergedCells.BackgroundColor = backgroundColor; 46 | 47 | return this; 48 | } 49 | 50 | public IExpectStylesOrBuildMergeBuilder SetMergingOutsideBorder(LineStyle borderLineStyle = LineStyle.Thin, Color borderColor = new()) 51 | { 52 | if (borderColor.IsEmpty) 53 | borderColor = Color.Black; 54 | 55 | MergedCells.OutsideBorder = new Border(borderLineStyle, borderColor); 56 | 57 | return this; 58 | } 59 | 60 | public IMergeBuilder Build() 61 | { 62 | if (CanBuild is false) 63 | throw new InvalidOperationException("Cannot build MergedCells because some necessary information are not provided"); 64 | 65 | return MergedCells; 66 | } 67 | } -------------------------------------------------------------------------------- /ExcelWizard/Models/EWRow/RowBuilderContracts.cs: -------------------------------------------------------------------------------- 1 | using ExcelWizard.Models.EWCell; 2 | using ExcelWizard.Models.EWMerge; 3 | using System.Collections.Generic; 4 | 5 | namespace ExcelWizard.Models.EWRow; 6 | 7 | public interface IRowBuilder 8 | { 9 | /// 10 | /// Get Current Row Y Location (RowNumber) 11 | /// 12 | /// 13 | int GetRowNumber(); 14 | 15 | int GetNextRowNumberAfterRow(); 16 | 17 | /// 18 | /// Get current Row Starting Cell Automatically by its Cells Location 19 | /// 20 | /// 21 | CellLocation GetRowFirstCellLocation(); 22 | 23 | /// 24 | /// Get current Row Ending Cell Automatically by its Cells Location 25 | /// 26 | /// 27 | CellLocation GetRowLastCellLocation(); 28 | 29 | CellLocation GetNextHorizontalCellLocationAfterRow(); 30 | Cell? GetRowCellByColumnNumber(int columnNumber); 31 | void ValidateRowInstance(); 32 | } 33 | 34 | public interface IExpectMergedCellsStatusRowBuilder 35 | { 36 | /// 37 | /// Define Location of Merged Cells in the current Row. The property is collection, in case 38 | /// we have multiple merged-cells definitions in different locations of the Row. Notice that the Merged-Cells 39 | /// RowNumber should match with the Row RowNumber itself, otherwise an error will throw. 40 | /// 41 | /// MergeBuilder with Build() method at the end 42 | /// MergeBuilder(s) with Build() method at the end of them 43 | IExpectStyleRowBuilder SetRowMergedCells(IMergeBuilder mergeBuilder, params IMergeBuilder[] mergeBuilders); 44 | 45 | /// 46 | /// Define Location of Merged Cells in the current Row. The property is collection, in case 47 | /// we have multiple merged-cells definitions in different locations of the Row. Notice that the Merged-Cells 48 | /// RowNumber should match with the Row RowNumber itself, otherwise an error will throw. 49 | /// 50 | /// MergeBuilders with Build() method at the end of them 51 | IExpectStyleRowBuilder SetRowMergedCells(List mergeBuilders); 52 | 53 | /// 54 | /// In case we don't have any merge in the Row 55 | /// 56 | /// 57 | IExpectStyleRowBuilder RowHasNoMerging(); 58 | } 59 | 60 | public interface IExpectStyleRowBuilder 61 | { 62 | /// 63 | /// Set Row Styles including Bg, Font, Height, Borders and etc 64 | /// 65 | IExpectBuildMethodRowBuilder SetRowStyle(RowStyle rowStyle); 66 | 67 | /// 68 | /// No custom styles for the row 69 | /// 70 | IExpectBuildMethodRowBuilder RowHasNoCustomStyle(); 71 | } 72 | 73 | public interface IExpectBuildMethodRowBuilder 74 | { 75 | IRowBuilder Build(); 76 | } -------------------------------------------------------------------------------- /samples/BlazorApp/wwwroot/css/app.css: -------------------------------------------------------------------------------- 1 | @import url('open-iconic/font/css/open-iconic-bootstrap.min.css'); 2 | 3 | html, body { 4 | font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; 5 | } 6 | 7 | h1:focus { 8 | outline: none; 9 | } 10 | 11 | a, .btn-link { 12 | color: #0071c1; 13 | } 14 | 15 | .btn-primary { 16 | color: #fff; 17 | background-color: #1b6ec2; 18 | border-color: #1861ac; 19 | } 20 | 21 | .content { 22 | padding-top: 1.1rem; 23 | } 24 | 25 | .valid.modified:not([type=checkbox]) { 26 | outline: 1px solid #26b050; 27 | } 28 | 29 | .invalid { 30 | outline: 1px solid red; 31 | } 32 | 33 | .validation-message { 34 | color: red; 35 | } 36 | 37 | #blazor-error-ui { 38 | background: lightyellow; 39 | bottom: 0; 40 | box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2); 41 | display: none; 42 | left: 0; 43 | padding: 0.6rem 1.25rem 0.7rem 1.25rem; 44 | position: fixed; 45 | width: 100%; 46 | z-index: 1000; 47 | } 48 | 49 | #blazor-error-ui .dismiss { 50 | cursor: pointer; 51 | position: absolute; 52 | right: 0.75rem; 53 | top: 0.5rem; 54 | } 55 | 56 | .blazor-error-boundary { 57 | background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121; 58 | padding: 1rem 1rem 1rem 3.7rem; 59 | color: white; 60 | } 61 | 62 | .blazor-error-boundary::after { 63 | content: "An error has occurred." 64 | } 65 | -------------------------------------------------------------------------------- /ExcelWizard/Models/EWGridLayout/ExcelSheetAttribute.cs: -------------------------------------------------------------------------------- 1 | using ExcelWizard.Models.EWStyles; 2 | using System; 3 | using System.Drawing; 4 | 5 | namespace ExcelWizard.Models.EWGridLayout; 6 | 7 | /// 8 | /// Configure the Excel generic properties in a grid layout Excel schema 9 | /// 10 | [AttributeUsage(AttributeTargets.Class)] 11 | public class ExcelSheetAttribute : Attribute 12 | { 13 | /// 14 | /// Sheet direction 15 | /// 16 | public SheetDirection SheetDirection { get; set; } = SheetDirection.LeftToRight; 17 | 18 | /// 19 | /// Sheet name of generated Excel that contains the Class data. The default is Sheet1, Sheet2, etc.. 20 | /// 21 | public string? SheetName { get; set; } 22 | 23 | /// 24 | /// Default text align including both header and data cells. It can be overridden for header as well as data cells 25 | /// 26 | public TextAlign DefaultTextAlign { get; set; } = TextAlign.Center; 27 | 28 | /// 29 | /// Sheet Header Height. 0 will revert to default 30 | /// 31 | public int HeaderHeight { get; set; } 32 | 33 | /// 34 | /// Sheet Header Background Color 35 | /// 36 | public KnownColor HeaderBackgroundColor { get; set; } = KnownColor.Transparent; 37 | 38 | /// 39 | /// Sheet Each Data Row Height 40 | /// 41 | public int DataRowHeight { get; set; } 42 | 43 | /// 44 | /// Sheet Cells FontFamily Name 45 | /// 46 | public string? FontName { get; set; } 47 | 48 | /// 49 | /// Sheet Cells FontColor 50 | /// 51 | public KnownColor FontColor { get; set; } = KnownColor.Black; 52 | 53 | /// 54 | /// Sheets Cells FontSize. If 0 it means default FontSize 55 | /// 56 | public int FontSize { get; set; } 57 | 58 | /// 59 | /// Font Weight for entire Sheet. Inherit is equal to default here which is bold for Header and normal for Cells 60 | /// 61 | public FontWeight FontWeight { get; set; } = FontWeight.Inherit; 62 | 63 | /// 64 | /// Sheet All Data Cells Background 65 | /// 66 | public KnownColor DataBackgroundColor { get; set; } = KnownColor.Transparent; 67 | 68 | /// 69 | /// All Borders Type 70 | /// 71 | public LineStyle BorderType { get; set; } = LineStyle.Thin; 72 | 73 | /// 74 | /// All Borders Color 75 | /// 76 | public KnownColor BorderColor { get; set; } = KnownColor.LightGray; 77 | 78 | /// 79 | /// Are Sheet Cells Locked? Meaning you cannot edit/delete Cells data but the Sheet can still be formatted 80 | /// 81 | public bool IsSheetLocked { get; set; } 82 | 83 | /// 84 | /// The Sheet will be hardly protected and you cannot format/delete Cells/Rows/Columns or edit any objects 85 | /// 86 | public bool IsSheetHardProtected { get; set; } 87 | } -------------------------------------------------------------------------------- /ExcelWizard/Models/EWCell/CellBuilder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ExcelWizard.Models.EWCell; 4 | 5 | public class CellBuilder 6 | { 7 | private CellBuilder() { } 8 | 9 | private Cell Cell { get; set; } = new(); 10 | private static bool CanBuild { get; set; } 11 | 12 | /// 13 | /// Set Cell location (X/Column and Y/Row) 14 | /// 15 | /// [X]; Cell Column Letter (e.g. "B") or Cell Column Number (e.g. 2) 16 | /// [Y]; Cell Row Number 17 | public static CellBuilder SetLocation(dynamic columnLetterOrNumber, int rowNumber) 18 | { 19 | CanBuild = true; 20 | 21 | return new CellBuilder 22 | { 23 | Cell = new Cell 24 | { 25 | CellLocation = new CellLocation(columnLetterOrNumber, rowNumber) 26 | } 27 | }; 28 | } 29 | 30 | /// 31 | /// Set Cell Value that is displayed 32 | /// 33 | /// Cell Content Value 34 | public CellBuilder SetValue(object? value) 35 | { 36 | Cell.CellValue = value; 37 | 38 | return this; 39 | } 40 | 41 | /// 42 | /// Set an arbitrary property to distinguish the Cells. For example can be the db Id (which are not suppose to be shown in the Excel) 43 | /// 44 | /// Cell unique identifier 45 | public CellBuilder SetIdentifier(string? identifier) 46 | { 47 | Cell.CellIdentifier = identifier; 48 | 49 | return this; 50 | } 51 | 52 | /// 53 | /// Set content type of Cell e.g. text, currency, date, number, etc. 54 | /// 55 | /// 56 | public CellBuilder SetContentType(CellContentType contentType) 57 | { 58 | Cell.CellContentType = contentType; 59 | 60 | return this; 61 | } 62 | 63 | /// 64 | /// Set Cell Styles including Font, Wrap behaviour, Align and etc 65 | /// 66 | public CellBuilder SetCellStyle(CellStyle cellStyle) 67 | { 68 | Cell.CellStyle = cellStyle; 69 | 70 | return this; 71 | } 72 | 73 | /// 74 | /// Show / Hide Cell Content in Generated Excel 75 | /// 76 | /// 77 | public CellBuilder SetContentVisibility(bool isVisible) 78 | { 79 | Cell.IsCellVisible = isVisible; 80 | 81 | return this; 82 | } 83 | 84 | /// 85 | /// Will override the IsSheetLocked property of Sheet model if set to a value. Default will inherit 86 | /// 87 | public CellBuilder SetLockStatus(bool isLocked) 88 | { 89 | Cell.IsCellLocked = isLocked; 90 | 91 | return this; 92 | } 93 | 94 | public Cell Build() 95 | { 96 | if (CanBuild is false) 97 | throw new InvalidOperationException("Cannot build Cell because its location is undefined"); 98 | 99 | return Cell; 100 | } 101 | } -------------------------------------------------------------------------------- /ExcelWizard/ExcelWizardExtensions.cs: -------------------------------------------------------------------------------- 1 | using BlazorDownloadFile; 2 | using ExcelWizard.Service; 3 | using Microsoft.Extensions.DependencyInjection; 4 | using System; 5 | 6 | namespace ExcelWizard; 7 | 8 | public static class ExcelWizardExtensions 9 | { 10 | /// 11 | /// Add ExcelWizard package required services to IServiceCollection 12 | /// 13 | /// 14 | /// Do you register for a Blazor app or not. In case of API or MVC project, is will be false 15 | /// LifeTime of Dependency Injection 16 | public static void AddExcelWizardServices(this IServiceCollection services, bool isBlazorApp = false, ServiceLifetime lifetime = ServiceLifetime.Scoped) 17 | { 18 | if (isBlazorApp) 19 | services.AddBlazorDownloadFile(lifetime); 20 | 21 | if (lifetime == ServiceLifetime.Scoped) 22 | { 23 | services.AddScoped(); 24 | 25 | if (isBlazorApp is false) 26 | services.AddScoped(); 27 | } 28 | 29 | else if (lifetime == ServiceLifetime.Transient) 30 | { 31 | services.AddTransient(); 32 | 33 | if (isBlazorApp is false) 34 | services.AddTransient(); 35 | } 36 | 37 | else if (lifetime == ServiceLifetime.Singleton) 38 | { 39 | services.AddSingleton(); 40 | 41 | if (isBlazorApp is false) 42 | services.AddSingleton(); 43 | } 44 | 45 | else 46 | { 47 | throw new InvalidOperationException("The lifeTime is invalid"); 48 | } 49 | } 50 | 51 | /// 52 | /// Get Cell Column Number from Cell Column Letter, e.g. "A" => 1 or "C" => 3 53 | /// 54 | public static int GetCellColumnNumberByCellColumnLetter(this string cellColumnLetter) 55 | { 56 | int retVal = 0; 57 | string col = cellColumnLetter.ToUpper(); 58 | for (int iChar = col.Length - 1; iChar >= 0; iChar--) 59 | { 60 | char colPiece = col[iChar]; 61 | int colNum = colPiece - 64; 62 | retVal = retVal + colNum * (int)Math.Pow(26, col.Length - (iChar + 1)); 63 | } 64 | return retVal; 65 | } 66 | 67 | /// 68 | /// Get Cell Column Letter By Cell Column Number, e.g. 1 => "A" or 3 => "C" 69 | /// 70 | /// 71 | /// 72 | public static string GetCellColumnLetterByCellColumnNumber(this int cellColumnNumber) 73 | { 74 | int dividend = cellColumnNumber; 75 | 76 | string cellName = string.Empty; 77 | 78 | while (dividend > 0) 79 | { 80 | var modulo = (dividend - 1) % 26; 81 | cellName = Convert.ToChar(65 + modulo) + cellName; 82 | dividend = (dividend - modulo) / 26; 83 | } 84 | 85 | return cellName.ToUpper(); 86 | } 87 | } -------------------------------------------------------------------------------- /ExcelWizard/Models/EWTable/ExcelTableAttribute.cs: -------------------------------------------------------------------------------- 1 | using ExcelWizard.Models.EWStyles; 2 | using System; 3 | using System.Drawing; 4 | 5 | namespace ExcelWizard.Models.EWTable; 6 | 7 | /// 8 | /// Configure the Table generic properties in a complex Excel schema 9 | /// 10 | [AttributeUsage(AttributeTargets.Class)] 11 | public class ExcelTableAttribute : Attribute 12 | { 13 | /// 14 | /// whether the table renders with header or without it 15 | /// 16 | public bool HasHeader { get; set; } = true; 17 | 18 | /// 19 | /// How many rows does the Header occupy. It will be merged automatically 20 | /// 21 | public int HeaderOccupyingRowsNo { get; set; } = 1; 22 | 23 | /// 24 | /// Table header background color. Will be ignored if HasHeader is set to false 25 | /// 26 | public KnownColor HeaderBackgroundColor { get; set; } = KnownColor.Transparent; 27 | 28 | /// 29 | /// Table header font color. Will be ignored if HasHeader is set to false 30 | /// 31 | public KnownColor HeaderFontColor { get; set; } = KnownColor.Black; 32 | 33 | /// 34 | /// Table header font weight. Will be ignored if HasHeader is set to false 35 | /// 36 | public FontWeight HeaderFontWeight { get; set; } = FontWeight.Inherit; 37 | 38 | /// 39 | /// Table Cells TextAlign 40 | /// 41 | public TextAlign TextAlign { get; set; } = TextAlign.Inherit; 42 | 43 | /// 44 | /// Table Cells FontFamily name 45 | /// 46 | public string? FontName { get; set; } 47 | 48 | /// 49 | /// Table Cells FontColor 50 | /// 51 | public KnownColor FontColor { get; set; } = KnownColor.Black; 52 | 53 | /// 54 | /// Table Cells FontSize. If 0 it means default FontSize 55 | /// 56 | public int FontSize { get; set; } 57 | 58 | /// 59 | /// Font Weight for entire Table. Inherit is equal to default here which is bold for Header and normal for Cells 60 | /// 61 | public FontWeight FontWeight { get; set; } = FontWeight.Inherit; 62 | 63 | /// 64 | /// Table all data Cells background 65 | /// 66 | public KnownColor DataBackgroundColor { get; set; } = KnownColor.Transparent; 67 | 68 | /// 69 | /// Set outside border of a table. Default is thin border. 70 | /// 71 | public LineStyle OutsideBorderStyle { get; set; } = LineStyle.Thin; 72 | 73 | /// 74 | /// Set outside border of a table. Default is color border. 75 | /// 76 | public KnownColor OutsideBorderColor { get; set; } = KnownColor.LightGray; 77 | 78 | /// 79 | /// Set style of inside borders of table Cells. It do not effect the table Outside borders! Default is Thin border (Like Excel normal cells) 80 | /// 81 | public LineStyle InsideCellsBorderStyle { get; set; } = LineStyle.Thin; 82 | 83 | /// 84 | /// Set color of inside borders of table Cells. It do not effect the table Outside borders! Default is Thin border (Like Excel normal cells) 85 | /// 86 | public KnownColor InsideCellsBorderColor { get; set; } = KnownColor.LightGray; 87 | } -------------------------------------------------------------------------------- /ExcelWizard/Models/EWRow/RowBuilder.cs: -------------------------------------------------------------------------------- 1 | using ExcelWizard.Models.EWCell; 2 | using ExcelWizard.Models.EWMerge; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | 7 | namespace ExcelWizard.Models.EWRow; 8 | 9 | public class RowBuilder : IExpectMergedCellsStatusRowBuilder, IExpectBuildMethodRowBuilder, IExpectStyleRowBuilder 10 | { 11 | private RowBuilder() { } 12 | 13 | private Row Row { get; set; } = new(); 14 | private bool CanBuild { get; set; } 15 | 16 | /// 17 | /// Each Row contains one or more Cell(s). It is required as Row definition cannot be without Cells. 18 | /// 19 | /// CellBuilder with Build() method at the end 20 | /// CellBuilder(s) with Build() method at the end of them 21 | public static IExpectMergedCellsStatusRowBuilder SetCells(ICellBuilder cellBuilder, params ICellBuilder[] cellBuilders) 22 | { 23 | ICellBuilder[] cells = new[] { cellBuilder }.Concat(cellBuilders).ToArray(); 24 | 25 | return new RowBuilder 26 | { 27 | Row = new Row 28 | { 29 | RowCells = cells.Select(c => (Cell)c).ToList() 30 | } 31 | }; 32 | } 33 | 34 | /// 35 | /// Each Row contains one or more Cell(s). It is required as Row definition cannot be without Cells. 36 | /// 37 | /// CellBuilders with Build() method at the end of them 38 | public static IExpectMergedCellsStatusRowBuilder SetCells(List cellBuilders) 39 | { 40 | return new RowBuilder 41 | { 42 | Row = new Row 43 | { 44 | RowCells = cellBuilders.Select(c => (Cell)c).ToList() 45 | } 46 | }; 47 | } 48 | 49 | /// 50 | /// (Showing comment in Interface) 51 | /// Define Location of Merged Cells in the current Row. The property is collection, in case 52 | /// we have multiple merged-cells definitions in different locations of the Row. Notice that the Merged-Cells 53 | /// RowNumber should match with the Row RowNumber itself, otherwise an error will throw. 54 | /// 55 | public IExpectStyleRowBuilder SetRowMergedCells(IMergeBuilder mergeBuilder, params IMergeBuilder[] mergeBuilders) 56 | { 57 | IMergeBuilder[] merges = new[] { mergeBuilder }.Concat(mergeBuilders).ToArray(); 58 | 59 | CanBuild = true; 60 | 61 | Row.MergedCellsList = merges.Select(m => (MergedCells)m).ToList(); 62 | 63 | return this; 64 | } 65 | 66 | public IExpectStyleRowBuilder SetRowMergedCells(List mergeBuilders) 67 | { 68 | CanBuild = true; 69 | 70 | Row.MergedCellsList = mergeBuilders.Select(m => (MergedCells)m).ToList(); 71 | 72 | return this; 73 | } 74 | 75 | /// 76 | /// (Showing comment in Interface) 77 | /// In case we don't have any merge in the Row 78 | /// 79 | /// 80 | public IExpectStyleRowBuilder RowHasNoMerging() 81 | { 82 | CanBuild = true; 83 | 84 | return this; 85 | } 86 | 87 | public IExpectBuildMethodRowBuilder SetRowStyle(RowStyle rowStyle) 88 | { 89 | Row.RowStyle = rowStyle; 90 | 91 | return this; 92 | } 93 | 94 | public IExpectBuildMethodRowBuilder RowHasNoCustomStyle() 95 | { 96 | return this; 97 | } 98 | 99 | public IRowBuilder Build() 100 | { 101 | if (CanBuild is false) 102 | throw new InvalidOperationException("Cannot build Row because some necessary information are not provided"); 103 | 104 | return Row; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /ExcelWizard.Tests/Models/EWCell/CellBuilderTests.cs: -------------------------------------------------------------------------------- 1 | using ExcelWizard.Models; 2 | using ExcelWizard.Models.EWCell; 3 | using ExcelWizard.Models.EWStyles; 4 | using System.Drawing; 5 | 6 | namespace ExcelWizard.Tests.Models.EWCell; 7 | 8 | public class CellBuilderTests 9 | { 10 | [Theory] 11 | [InlineData(1, 1, 2)] 12 | [InlineData("B", 2, 3)] 13 | public void SetLocation_WhenGivenColumnAndRow_ShouldSetCellLocation(dynamic columnLetterOrNumber, int columnNumber, int rowNumber) 14 | { 15 | // Act 16 | Cell cell = CellBuilder 17 | .SetLocation(columnLetterOrNumber, rowNumber) 18 | .Build(); 19 | 20 | // Assert 21 | cell.CellLocation.RowNumber.Should().Be(rowNumber); 22 | cell.CellLocation.ColumnNumber.Should().Be(columnNumber); 23 | } 24 | 25 | [Theory] 26 | [InlineData(null)] 27 | [InlineData(1)] 28 | [InlineData("foo")] 29 | public void SetValue_WhenGivenAValue_ShouldSetItAsCellValue(object? value) 30 | { 31 | // Act 32 | Cell cell = CellBuilder 33 | .SetLocation(It.IsAny(), It.IsAny()) 34 | .SetValue(value) 35 | .Build(); 36 | 37 | // Assert 38 | cell.CellValue.Should().BeEquivalentTo(value); 39 | } 40 | 41 | [Theory] 42 | [InlineData(null)] 43 | [InlineData("foo")] 44 | public void SetIdentifier_WhenGivenAnIdentifier_ShouldSetItAsCellIdentifier(string? identifier) 45 | { 46 | // Act 47 | Cell cell = CellBuilder 48 | .SetLocation(It.IsAny(), It.IsAny()) 49 | .SetIdentifier(identifier) 50 | .Build(); 51 | 52 | // Assert 53 | cell.CellIdentifier.Should().Be(identifier); 54 | } 55 | 56 | [Fact] 57 | public void SetContentType_WhenNotSpecifyAnyType_ShouldSetDefaultGeneralType() 58 | { 59 | // Act 60 | Cell cell = CellBuilder 61 | .SetLocation(It.IsAny(), It.IsAny()) 62 | .Build(); 63 | 64 | // Assert 65 | cell.CellContentType.Should().Be(CellContentType.General); 66 | } 67 | 68 | [Fact] 69 | public void SetContentType_WhenGivenAType_ShouldSetItAsCellContentType() 70 | { 71 | // Arrange 72 | var contentType = CellContentType.Number; 73 | 74 | // Act 75 | Cell cell = CellBuilder 76 | .SetLocation(It.IsAny(), It.IsAny()) 77 | .SetContentType(contentType) 78 | .Build(); 79 | 80 | // Assert 81 | cell.CellContentType.Should().Be(contentType); 82 | } 83 | 84 | [Fact] 85 | public void SetCellStyle_WhenGivenStyle_ShouldSetItAsCellStyle() 86 | { 87 | // Arrange 88 | var cellStyle = new CellStyle { Wordwrap = true, BackgroundColor = Color.Red, Font = new TextFont { FontName = "Foo" } }; 89 | 90 | // Act 91 | Cell cell = CellBuilder 92 | .SetLocation(It.IsAny(), It.IsAny()) 93 | .SetCellStyle(cellStyle) 94 | .Build(); 95 | 96 | // Assert 97 | cell.CellStyle.Should().Be(cellStyle); 98 | } 99 | 100 | [Fact] 101 | public void SetCellContentVisibility_WhenGivenIsVisibleFalse_ShouldSetCellIsContentVisibleTrue() 102 | { 103 | // Act 104 | Cell cell = CellBuilder 105 | .SetLocation(It.IsAny(), It.IsAny()) 106 | .Build(); 107 | 108 | // Assert 109 | cell.IsCellVisible.Should().BeTrue(); 110 | } 111 | 112 | [Fact] 113 | public void SetCellContentVisibility_WhenContentVisibilityIsNotSet_ShouldSetIsContentVisible() 114 | { 115 | var isVisible = false; 116 | 117 | // Act 118 | Cell cell = CellBuilder 119 | .SetLocation(It.IsAny(), It.IsAny()) 120 | .SetContentVisibility(isVisible) 121 | .Build(); 122 | 123 | // Assert 124 | cell.IsCellVisible.Should().BeFalse(); 125 | } 126 | } -------------------------------------------------------------------------------- /samples/BlazorApp/wwwroot/css/open-iconic/README.md: -------------------------------------------------------------------------------- 1 | [Open Iconic v1.1.1](http://useiconic.com/open) 2 | =========== 3 | 4 | ### Open Iconic is the open source sibling of [Iconic](http://useiconic.com). It is a hyper-legible collection of 223 icons with a tiny footprint—ready to use with Bootstrap and Foundation. [View the collection](http://useiconic.com/open#icons) 5 | 6 | 7 | 8 | ## What's in Open Iconic? 9 | 10 | * 223 icons designed to be legible down to 8 pixels 11 | * Super-light SVG files - 61.8 for the entire set 12 | * SVG sprite—the modern replacement for icon fonts 13 | * Webfont (EOT, OTF, SVG, TTF, WOFF), PNG and WebP formats 14 | * Webfont stylesheets (including versions for Bootstrap and Foundation) in CSS, LESS, SCSS and Stylus formats 15 | * PNG and WebP raster images in 8px, 16px, 24px, 32px, 48px and 64px. 16 | 17 | 18 | ## Getting Started 19 | 20 | #### For code samples and everything else you need to get started with Open Iconic, check out our [Icons](http://useiconic.com/open#icons) and [Reference](http://useiconic.com/open#reference) sections. 21 | 22 | ### General Usage 23 | 24 | #### Using Open Iconic's SVGs 25 | 26 | We like SVGs and we think they're the way to display icons on the web. Since Open Iconic are just basic SVGs, we suggest you display them like you would any other image (don't forget the `alt` attribute). 27 | 28 | ``` 29 | icon name 30 | ``` 31 | 32 | #### Using Open Iconic's SVG Sprite 33 | 34 | Open Iconic also comes in a SVG sprite which allows you to display all the icons in the set with a single request. It's like an icon font, without being a hack. 35 | 36 | Adding an icon from an SVG sprite is a little different than what you're used to, but it's still a piece of cake. *Tip: To make your icons easily style able, we suggest adding a general class to the* `` *tag and a unique class name for each different icon in the* `` *tag.* 37 | 38 | ``` 39 | 40 | 41 | 42 | ``` 43 | 44 | Sizing icons only needs basic CSS. All the icons are in a square format, so just set the `` tag with equal width and height dimensions. 45 | 46 | ``` 47 | .icon { 48 | width: 16px; 49 | height: 16px; 50 | } 51 | ``` 52 | 53 | Coloring icons is even easier. All you need to do is set the `fill` rule on the `` tag. 54 | 55 | ``` 56 | .icon-account-login { 57 | fill: #f00; 58 | } 59 | ``` 60 | 61 | To learn more about SVG Sprites, read [Chris Coyier's guide](http://css-tricks.com/svg-sprites-use-better-icon-fonts/). 62 | 63 | #### Using Open Iconic's Icon Font... 64 | 65 | 66 | ##### …with Bootstrap 67 | 68 | You can find our Bootstrap stylesheets in `font/css/open-iconic-bootstrap.{css, less, scss, styl}` 69 | 70 | 71 | ``` 72 | 73 | ``` 74 | 75 | 76 | ``` 77 | 78 | ``` 79 | 80 | ##### …with Foundation 81 | 82 | You can find our Foundation stylesheets in `font/css/open-iconic-foundation.{css, less, scss, styl}` 83 | 84 | ``` 85 | 86 | ``` 87 | 88 | 89 | ``` 90 | 91 | ``` 92 | 93 | ##### …on its own 94 | 95 | You can find our default stylesheets in `font/css/open-iconic.{css, less, scss, styl}` 96 | 97 | ``` 98 | 99 | ``` 100 | 101 | ``` 102 | 103 | ``` 104 | 105 | 106 | ## License 107 | 108 | ### Icons 109 | 110 | All code (including SVG markup) is under the [MIT License](http://opensource.org/licenses/MIT). 111 | 112 | ### Fonts 113 | 114 | All fonts are under the [SIL Licensed](http://scripts.sil.org/cms/scripts/page.php?item_id=OFL_web). 115 | -------------------------------------------------------------------------------- /ExcelWizard/Models/EWExcel/ExcelBuilderContracts.cs: -------------------------------------------------------------------------------- 1 | using ExcelWizard.Models.EWExcel; 2 | using ExcelWizard.Models.EWSheet; 3 | using System.Collections.Generic; 4 | 5 | namespace ExcelWizard.Models; 6 | 7 | public interface IExcelBuilder 8 | { 9 | 10 | } 11 | 12 | public interface IExpectGeneratingExcelTypeExcelBuilder 13 | { 14 | /// 15 | /// Generate simple Grid layout Excel file with the option of simply using a model bind and configure Excel with attributes 16 | /// 17 | IExpectGridLayoutExcelBuilder CreateGridLayoutExcel(); 18 | 19 | /// 20 | /// The Excel is not a grid layout Excel, therefore cannot be created through binding to a model and would be created composing different sub-components and configs 21 | /// 22 | IExpectSheetsExcelBuilder CreateComplexLayoutExcel(); 23 | } 24 | 25 | public interface IExpectSheetsExcelBuilder 26 | { 27 | /// 28 | /// Add one or more sheets to the Excel. It is required as Excel definition cannot be without Sheet(s). 29 | /// 30 | /// SheetBuilder with Build() method at the end 31 | /// SheetBuilder(s) with Build() method at the end of them 32 | IExpectStyleExcelBuilder SetSheets(ISheetBuilder sheetBuilder, params ISheetBuilder[] sheetBuilders); 33 | } 34 | 35 | public interface IExpectStyleExcelBuilder 36 | { 37 | /// 38 | /// All Sheets shared default styles including default ColumnWidth, default RowHeight and sheets language Direction 39 | /// 40 | IExpectOtherPropsAndBuildExcelBuilder SetSheetsDefaultStyle(SheetsDefaultStyle sheetsDefaultStyle); 41 | 42 | /// 43 | /// No custom default styles for sheet(s) will be set. Styles can be set on each Sheet individually 44 | /// 45 | IExpectOtherPropsAndBuildExcelBuilder SheetsHaveNoDefaultStyle(); 46 | } 47 | 48 | public interface IExpectOtherPropsAndBuildExcelBuilder : IExpectBuildExcelBuilder 49 | { 50 | /// 51 | /// Set the default IsLocked value for all Sheets. Default is false 52 | /// 53 | IExpectBuildExcelBuilder SetDefaultLockedStatus(bool isLockedByDefault); 54 | } 55 | 56 | public interface IExpectBuildExcelBuilder 57 | { 58 | IExcelBuilder Build(); 59 | } 60 | 61 | public interface IExpectGridLayoutExcelBuilder 62 | { 63 | /// 64 | /// Generate Simple Single Sheet Grid layout Excel file from special model configured options with [ExcelSheet] and [ExcelSheetColumn] attributes 65 | /// 66 | /// List of data (should be something like List{Person}()) 67 | IExpectBuildExcelBuilder WithOneSheetUsingModelBinding(object bindingListModel); 68 | 69 | /// 70 | /// Generate Grid layout Excel having multiple Sheets from different model types configured options with [ExcelSheet] and [ExcelSheetColumn] attributes. 71 | /// Here Sheet name will be get from model [ExcelSheet] attribute. 72 | /// 73 | /// List of data list. e.g. object list of Persons, Phones, Universities, etc which each will be mapped to a Sheet 74 | IExpectStyleExcelBuilder WithMultipleSheetsUsingModelBinding(List listOfBindingListModel); 75 | 76 | /// 77 | /// Generate Grid layout Excel having multiple Sheets from same model types configured options with [ExcelSheet] and [ExcelSheetColumn] attributes 78 | /// Here Sheet names can be get from argument and not from model attribute. 79 | /// 80 | /// List of data list. e.g. object list of Persons, Phones, Universities, etc which each will be mapped to a Sheet 81 | IExpectStyleExcelBuilder WithMultipleSheetsUsingModelBinding(List bindingSheets); 82 | 83 | /// 84 | /// Generate Grid layout Excel in usual way by create Sheets manually step by step and without model binding 85 | /// 86 | /// 87 | IExpectSheetsExcelBuilder ManuallyWithoutModelBinding(); 88 | } 89 | -------------------------------------------------------------------------------- /samples/BlazorApp/wwwroot/css/open-iconic/FONT-LICENSE: -------------------------------------------------------------------------------- 1 | SIL OPEN FONT LICENSE Version 1.1 2 | 3 | Copyright (c) 2014 Waybury 4 | 5 | PREAMBLE 6 | The goals of the Open Font License (OFL) are to stimulate worldwide 7 | development of collaborative font projects, to support the font creation 8 | efforts of academic and linguistic communities, and to provide a free and 9 | open framework in which fonts may be shared and improved in partnership 10 | with others. 11 | 12 | The OFL allows the licensed fonts to be used, studied, modified and 13 | redistributed freely as long as they are not sold by themselves. The 14 | fonts, including any derivative works, can be bundled, embedded, 15 | redistributed and/or sold with any software provided that any reserved 16 | names are not used by derivative works. The fonts and derivatives, 17 | however, cannot be released under any other type of license. The 18 | requirement for fonts to remain under this license does not apply 19 | to any document created using the fonts or their derivatives. 20 | 21 | DEFINITIONS 22 | "Font Software" refers to the set of files released by the Copyright 23 | Holder(s) under this license and clearly marked as such. This may 24 | include source files, build scripts and documentation. 25 | 26 | "Reserved Font Name" refers to any names specified as such after the 27 | copyright statement(s). 28 | 29 | "Original Version" refers to the collection of Font Software components as 30 | distributed by the Copyright Holder(s). 31 | 32 | "Modified Version" refers to any derivative made by adding to, deleting, 33 | or substituting -- in part or in whole -- any of the components of the 34 | Original Version, by changing formats or by porting the Font Software to a 35 | new environment. 36 | 37 | "Author" refers to any designer, engineer, programmer, technical 38 | writer or other person who contributed to the Font Software. 39 | 40 | PERMISSION & CONDITIONS 41 | Permission is hereby granted, free of charge, to any person obtaining 42 | a copy of the Font Software, to use, study, copy, merge, embed, modify, 43 | redistribute, and sell modified and unmodified copies of the Font 44 | Software, subject to the following conditions: 45 | 46 | 1) Neither the Font Software nor any of its individual components, 47 | in Original or Modified Versions, may be sold by itself. 48 | 49 | 2) Original or Modified Versions of the Font Software may be bundled, 50 | redistributed and/or sold with any software, provided that each copy 51 | contains the above copyright notice and this license. These can be 52 | included either as stand-alone text files, human-readable headers or 53 | in the appropriate machine-readable metadata fields within text or 54 | binary files as long as those fields can be easily viewed by the user. 55 | 56 | 3) No Modified Version of the Font Software may use the Reserved Font 57 | Name(s) unless explicit written permission is granted by the corresponding 58 | Copyright Holder. This restriction only applies to the primary font name as 59 | presented to the users. 60 | 61 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font 62 | Software shall not be used to promote, endorse or advertise any 63 | Modified Version, except to acknowledge the contribution(s) of the 64 | Copyright Holder(s) and the Author(s) or with their explicit written 65 | permission. 66 | 67 | 5) The Font Software, modified or unmodified, in part or in whole, 68 | must be distributed entirely under this license, and must not be 69 | distributed under any other license. The requirement for fonts to 70 | remain under this license does not apply to any document created 71 | using the Font Software. 72 | 73 | TERMINATION 74 | This license becomes null and void if any of the above conditions are 75 | not met. 76 | 77 | DISCLAIMER 78 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 79 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF 80 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 81 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE 82 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 83 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 84 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 85 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM 86 | OTHER DEALINGS IN THE FONT SOFTWARE. 87 | -------------------------------------------------------------------------------- /ExcelWizard/Models/EWSheet/SheetBuilder.cs: -------------------------------------------------------------------------------- 1 | using ExcelWizard.Models.EWCell; 2 | using ExcelWizard.Models.EWMerge; 3 | using ExcelWizard.Models.EWRow; 4 | using ExcelWizard.Models.EWTable; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | 9 | namespace ExcelWizard.Models.EWSheet; 10 | 11 | public class SheetBuilder : IExpectSetComponentsSheetBuilder, 12 | IExpectStyleSheetBuilder, IExpectOtherPropsAndBuildSheetBuilder, IExpectProtectionLevelSheetBuilder 13 | { 14 | private SheetBuilder() { } 15 | 16 | private Sheet Sheet { get; set; } = new(); 17 | private bool CanBuild { get; set; } 18 | 19 | /// 20 | /// Set the Sheet name 21 | /// 22 | /// Name of the Sheet 23 | public static IExpectSetComponentsSheetBuilder SetName(string? sheetName) 24 | { 25 | if (string.IsNullOrWhiteSpace(sheetName)) 26 | throw new ArgumentException("Sheet name cannot be empty"); 27 | 28 | return new SheetBuilder 29 | { 30 | Sheet = new Sheet 31 | { 32 | SheetName = sheetName 33 | } 34 | }; 35 | } 36 | 37 | public IExpectSetComponentsSheetBuilder SetTables(ITableBuilder tableBuilder, params ITableBuilder[] tableBuilders) 38 | { 39 | ITableBuilder[] tables = new[] { tableBuilder }.Concat(tableBuilders).ToArray(); 40 | 41 | Sheet.SheetTables.AddRange(tables.Select(t => (Table)t)); 42 | 43 | return this; 44 | } 45 | 46 | public IExpectSetComponentsSheetBuilder SetTables(List tableBuilders) 47 | { 48 | Sheet.SheetTables.AddRange(tableBuilders.Select(t => (Table)t)); 49 | 50 | return this; 51 | } 52 | 53 | public IExpectSetComponentsSheetBuilder SetRows(IRowBuilder rowBuilder, params IRowBuilder[] rowBuilders) 54 | { 55 | IRowBuilder[] rows = new[] { rowBuilder }.Concat(rowBuilders).ToArray(); 56 | 57 | Sheet.SheetRows.AddRange(rows.Select(r => (Row)r)); 58 | 59 | return this; 60 | } 61 | 62 | public IExpectSetComponentsSheetBuilder SetRows(List rowBuilders) 63 | { 64 | Sheet.SheetRows.AddRange(rowBuilders.Select(r => (Row)r)); 65 | 66 | return this; 67 | } 68 | 69 | public IExpectSetComponentsSheetBuilder SetCells(ICellBuilder cellBuilder, params ICellBuilder[] cellBuilders) 70 | { 71 | ICellBuilder[] cells = new[] { cellBuilder }.Concat(cellBuilders).ToArray(); 72 | 73 | Sheet.SheetCells.AddRange(cells.Select(c => (Cell)c).ToList()); 74 | 75 | return this; 76 | } 77 | 78 | public IExpectSetComponentsSheetBuilder SetCells(List cellBuilders) 79 | { 80 | Sheet.SheetCells.AddRange(cellBuilders.Select(c => (Cell)c).ToList()); 81 | 82 | return this; 83 | } 84 | 85 | public IExpectStyleSheetBuilder NoMoreTablesRowsOrCells() 86 | { 87 | return this; 88 | } 89 | 90 | public IExpectOtherPropsAndBuildSheetBuilder SetMergedCells(params IMergeBuilder[] mergeBuilders) 91 | { 92 | Sheet.MergedCellsList = mergeBuilders.Select(m => (MergedCells)m).ToList(); 93 | 94 | return this; 95 | } 96 | 97 | public IExpectOtherPropsAndBuildSheetBuilder SetSheetStyle(SheetStyle sheetStyle) 98 | { 99 | Sheet.SheetStyle = sheetStyle; 100 | 101 | CanBuild = true; 102 | 103 | return this; 104 | } 105 | 106 | public IExpectOtherPropsAndBuildSheetBuilder SheetHasNoCustomStyle() 107 | { 108 | CanBuild = true; 109 | 110 | return this; 111 | } 112 | 113 | public IExpectOtherPropsAndBuildSheetBuilder SetSheetLocked(bool isLocked) 114 | { 115 | Sheet.IsSheetLocked = isLocked; 116 | 117 | return this; 118 | } 119 | 120 | public IExpectOtherPropsAndBuildSheetBuilder SetProtectionLevel(ProtectionLevel protectionLevel) 121 | { 122 | Sheet.SheetProtectionLevel = protectionLevel; 123 | 124 | return this; 125 | } 126 | 127 | public IExpectProtectionLevelSheetBuilder SetSheetProtected() 128 | { 129 | Sheet.IsSheetProtected = true; 130 | 131 | return this; 132 | } 133 | 134 | public ISheetBuilder Build() 135 | { 136 | if (CanBuild is false) 137 | throw new InvalidOperationException("Cannot build Sheet because some necessary information are not provided"); 138 | 139 | return Sheet; 140 | } 141 | } -------------------------------------------------------------------------------- /ExcelWizard.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.1.32210.238 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{6C2DD239-0574-4F8B-84F5-678A0A58BEDF}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ApiApp", "ApiApp", "{5D50B9DE-A302-4185-A9F5-17DCCE6D2D08}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BlazorApp", "BlazorApp", "{3E1B6E7D-8904-4EE5-BE51-3D89E6D870B5}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiApp", "samples\ApiApp\ApiApp.csproj", "{426BE6D5-4672-48F3-AF6C-9D95C083B515}" 13 | EndProject 14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorApp", "samples\BlazorApp\BlazorApp.csproj", "{5B107EC1-7D25-430B-B8A3-A2560BBA6BF5}" 15 | EndProject 16 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8C405FC4-D38B-493C-94B1-43005080B037}" 17 | ProjectSection(SolutionItems) = preProject 18 | .gitignore = .gitignore 19 | README.md = README.md 20 | EndProjectSection 21 | EndProject 22 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Screenshots", "Screenshots", "{0B23C4ED-1435-41F1-A4DB-34C761F42C63}" 23 | ProjectSection(SolutionItems) = preProject 24 | ..\..\Users\fdavo\Desktop\accounts-excel-template-report.png = ..\..\Users\fdavo\Desktop\accounts-excel-template-report.png 25 | screenshots\Screenshot-1.png = screenshots\Screenshot-1.png 26 | screenshots\Screenshot-2.png = screenshots\Screenshot-2.png 27 | screenshots\Screenshot-3.png = screenshots\Screenshot-3.png 28 | screenshots\Screenshot-4.png = screenshots\Screenshot-4.png 29 | screenshots\Screenshot-5.png = screenshots\Screenshot-5.png 30 | EndProjectSection 31 | EndProject 32 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExcelWizard", "ExcelWizard\ExcelWizard.csproj", "{ABF861FA-5D72-491E-8CB9-77791BA6DB8B}" 33 | EndProject 34 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Templates", "Templates", "{5F155EF8-7E32-47D8-ABFE-B45B7B2CADC4}" 35 | ProjectSection(SolutionItems) = preProject 36 | templates\ComplexExcelTemplate.xlsx = templates\ComplexExcelTemplate.xlsx 37 | EndProjectSection 38 | EndProject 39 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExcelWizard.Tests", "ExcelWizard.Tests\ExcelWizard.Tests.csproj", "{0BFE5D3A-D0D4-492E-A28B-09A7B6621FEA}" 40 | EndProject 41 | Global 42 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 43 | Debug|Any CPU = Debug|Any CPU 44 | Release|Any CPU = Release|Any CPU 45 | EndGlobalSection 46 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 47 | {426BE6D5-4672-48F3-AF6C-9D95C083B515}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 48 | {426BE6D5-4672-48F3-AF6C-9D95C083B515}.Debug|Any CPU.Build.0 = Debug|Any CPU 49 | {426BE6D5-4672-48F3-AF6C-9D95C083B515}.Release|Any CPU.ActiveCfg = Release|Any CPU 50 | {426BE6D5-4672-48F3-AF6C-9D95C083B515}.Release|Any CPU.Build.0 = Release|Any CPU 51 | {5B107EC1-7D25-430B-B8A3-A2560BBA6BF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 52 | {5B107EC1-7D25-430B-B8A3-A2560BBA6BF5}.Debug|Any CPU.Build.0 = Debug|Any CPU 53 | {5B107EC1-7D25-430B-B8A3-A2560BBA6BF5}.Release|Any CPU.ActiveCfg = Release|Any CPU 54 | {5B107EC1-7D25-430B-B8A3-A2560BBA6BF5}.Release|Any CPU.Build.0 = Release|Any CPU 55 | {ABF861FA-5D72-491E-8CB9-77791BA6DB8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 56 | {ABF861FA-5D72-491E-8CB9-77791BA6DB8B}.Debug|Any CPU.Build.0 = Debug|Any CPU 57 | {ABF861FA-5D72-491E-8CB9-77791BA6DB8B}.Release|Any CPU.ActiveCfg = Release|Any CPU 58 | {ABF861FA-5D72-491E-8CB9-77791BA6DB8B}.Release|Any CPU.Build.0 = Release|Any CPU 59 | {0BFE5D3A-D0D4-492E-A28B-09A7B6621FEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 60 | {0BFE5D3A-D0D4-492E-A28B-09A7B6621FEA}.Debug|Any CPU.Build.0 = Debug|Any CPU 61 | {0BFE5D3A-D0D4-492E-A28B-09A7B6621FEA}.Release|Any CPU.ActiveCfg = Release|Any CPU 62 | {0BFE5D3A-D0D4-492E-A28B-09A7B6621FEA}.Release|Any CPU.Build.0 = Release|Any CPU 63 | EndGlobalSection 64 | GlobalSection(SolutionProperties) = preSolution 65 | HideSolutionNode = FALSE 66 | EndGlobalSection 67 | GlobalSection(NestedProjects) = preSolution 68 | {5D50B9DE-A302-4185-A9F5-17DCCE6D2D08} = {6C2DD239-0574-4F8B-84F5-678A0A58BEDF} 69 | {3E1B6E7D-8904-4EE5-BE51-3D89E6D870B5} = {6C2DD239-0574-4F8B-84F5-678A0A58BEDF} 70 | {426BE6D5-4672-48F3-AF6C-9D95C083B515} = {5D50B9DE-A302-4185-A9F5-17DCCE6D2D08} 71 | {5B107EC1-7D25-430B-B8A3-A2560BBA6BF5} = {3E1B6E7D-8904-4EE5-BE51-3D89E6D870B5} 72 | {0B23C4ED-1435-41F1-A4DB-34C761F42C63} = {8C405FC4-D38B-493C-94B1-43005080B037} 73 | {5F155EF8-7E32-47D8-ABFE-B45B7B2CADC4} = {8C405FC4-D38B-493C-94B1-43005080B037} 74 | EndGlobalSection 75 | GlobalSection(ExtensibilityGlobals) = postSolution 76 | SolutionGuid = {4D9AE86C-5CA6-4159-8131-2ED56F560667} 77 | EndGlobalSection 78 | EndGlobal 79 | -------------------------------------------------------------------------------- /ExcelWizard/Models/EWRow/Row.cs: -------------------------------------------------------------------------------- 1 | using ExcelWizard.Models.EWCell; 2 | using ExcelWizard.Models.EWMerge; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.Linq; 6 | 7 | namespace ExcelWizard.Models.EWRow; 8 | 9 | public class Row : IRowBuilder 10 | { 11 | // Props 12 | 13 | /// 14 | /// Each Row contains one or more Cell(s). It is required as Row definition cannot be without Cells. 15 | /// 16 | public List RowCells { get; internal set; } = new(); 17 | 18 | /// 19 | /// Set Row Styles including Bg, Font, Height, Borders and etc 20 | /// 21 | public RowStyle RowStyle { get; internal set; } = new(); 22 | 23 | /// 24 | /// Arbitrary property to define Location of Merged Cells in the current Row. The property is collection, in case 25 | /// we have multiple merged-cells definitions in different locations of the Row. Notice that the Merged-Cells 26 | /// RowNumber should match with the Row RowNumber itself, otherwise an error will throw. 27 | /// 28 | public List MergedCellsList { get; internal set; } = new(); 29 | 30 | // Methods 31 | 32 | /// 33 | /// Get Current Row Y Location (RowNumber) 34 | /// 35 | /// 36 | public int GetRowNumber() 37 | { 38 | return RowCells.First().CellLocation.RowNumber; 39 | } 40 | 41 | public int GetNextRowNumberAfterRow() 42 | { 43 | return GetRowNumber() + 1; 44 | } 45 | 46 | /// 47 | /// Get current Row Starting Cell Automatically by its Cells Location 48 | /// 49 | /// 50 | public CellLocation GetRowFirstCellLocation() 51 | { 52 | var rowColumns = RowCells.Select(c => c.CellLocation.ColumnNumber).ToList(); 53 | 54 | var rowNumber = RowCells.First().CellLocation.RowNumber; //All Cells in a Row have equal RowNumber 55 | 56 | return new CellLocation(rowColumns.Min(), rowNumber); 57 | } 58 | 59 | /// 60 | /// Get current Row Ending Cell Automatically by its Cells Location 61 | /// 62 | /// 63 | public CellLocation GetRowLastCellLocation() 64 | { 65 | var rowColumns = RowCells.Select(c => c.CellLocation.ColumnNumber).ToList(); 66 | 67 | var rowNumber = RowCells.First().CellLocation.RowNumber; //All Cells in a Row have equal RowNumber 68 | 69 | return new CellLocation(rowColumns.Max(), rowNumber); 70 | } 71 | 72 | public CellLocation GetNextHorizontalCellLocationAfterRow() 73 | { 74 | var rowEndLocation = GetRowLastCellLocation(); 75 | 76 | return new CellLocation(rowEndLocation.ColumnNumber + 1, rowEndLocation.RowNumber); 77 | } 78 | 79 | public Cell? GetRowCellByColumnNumber(int columnNumber) 80 | { 81 | return RowCells.FirstOrDefault(c => c.CellLocation.ColumnNumber == columnNumber); 82 | } 83 | 84 | // Validations 85 | public void ValidateRowInstance() 86 | { 87 | // Row definition cannot have no Cells 88 | if (RowCells.Count == 0) 89 | throw new ValidationException("Row instance should contain one or more Cell(s)"); 90 | 91 | // Check Y of StartLocation and EndLocation should be the equal and same with other Cells location Y property (Check with Shahab) 92 | if (RowCells.Select(c => c.CellLocation.RowNumber).Distinct().ToList().Count != 1) 93 | throw new ValidationException("Invalid Row. All Row Cells should have equal RowNumber!"); 94 | 95 | // Check MergedCells format 96 | var currentRowNumber = RowCells.First().CellLocation.RowNumber; 97 | 98 | foreach (var cellsToMerge in MergedCellsList) 99 | { 100 | if (cellsToMerge.MergedBoundaryLocation.StartCellLocation is null || cellsToMerge.MergedBoundaryLocation.FinishCellLocation is null) 101 | throw new ValidationException("Something is not right about MergedCells format. FirstCellLocation and LastCellLocations cannot be null"); 102 | 103 | if (cellsToMerge.MergedBoundaryLocation.StartCellLocation!.RowNumber != currentRowNumber) 104 | throw new ValidationException("Something is not right about MergedCells format. The RowNumber of FirstCellLocation should be equal with the Row RowNumber!"); 105 | 106 | if (cellsToMerge.MergedBoundaryLocation.FinishCellLocation!.RowNumber != currentRowNumber) 107 | throw new ValidationException("Something is not right about MergedCells format. The RowNumber of LastCellLocation should be equal with the Row RowNumber!"); 108 | } 109 | 110 | // Check all Cells be Unique (not repetitive) 111 | var isAllCellsUnique = RowCells.Select(c => c.CellLocation.ColumnNumber).Distinct().Count() == RowCells.Count; 112 | 113 | if (isAllCellsUnique is false) 114 | throw new ValidationException("There are some repetitive cells in the Row. All cells should be unique in a Row"); 115 | 116 | } 117 | } -------------------------------------------------------------------------------- /ExcelWizard/Models/EWSheet/SheetBuilderContracts.cs: -------------------------------------------------------------------------------- 1 | using ExcelWizard.Models.EWCell; 2 | using ExcelWizard.Models.EWMerge; 3 | using ExcelWizard.Models.EWRow; 4 | using ExcelWizard.Models.EWTable; 5 | using System.Collections.Generic; 6 | 7 | namespace ExcelWizard.Models.EWSheet; 8 | 9 | public interface ISheetBuilder 10 | { 11 | 12 | } 13 | 14 | public interface IExpectSetComponentsSheetBuilder 15 | { 16 | /// 17 | /// Insert one or more Table(s) data into the Sheet. 18 | /// Each Table is consist of some Rows and Cells with more style options to configure easily 19 | /// 20 | /// TableBuilder with Build() method at the end 21 | /// TableBuilder(s) with Build() method at the end of them 22 | IExpectSetComponentsSheetBuilder SetTables(ITableBuilder tableBuilder, params ITableBuilder[] tableBuilders); 23 | 24 | /// 25 | /// Insert one or more Table(s) data into the Sheet. 26 | /// Each Table is consist of some Rows and Cells with more style options to configure easily 27 | /// 28 | /// TableBuilders with Build() method at the end of them 29 | IExpectSetComponentsSheetBuilder SetTables(List tableBuilders); 30 | 31 | /// 32 | /// Insert one or more Row(s) records into the Sheet. 33 | /// Each Row is consist of some Cells with more style options to configure easily 34 | /// 35 | /// RowBuilder with Build() method at the end 36 | /// RowBuilder(s) with Build() method at the end of them 37 | IExpectSetComponentsSheetBuilder SetRows(IRowBuilder rowBuilder, params IRowBuilder[] rowBuilders); 38 | 39 | /// 40 | /// Insert one or more Row(s) records into the Sheet. 41 | /// Each Row is consist of some Cells with more style options to configure easily 42 | /// 43 | /// RowBuilders with Build() method at the end of them 44 | IExpectSetComponentsSheetBuilder SetRows(List rowBuilders); 45 | 46 | /// 47 | /// Insert one or more Cell(s) items directly into the Sheet. 48 | /// All data can be inserted with this property, but using Tables and Rows add more options to configure style and functionality of generated Sheet. 49 | /// 50 | /// CellBuilder with Build() method at the end 51 | /// CellBuilder(s) with Build() method at the end of them 52 | IExpectSetComponentsSheetBuilder SetCells(ICellBuilder cellBuilder, params ICellBuilder[] cellBuilders); 53 | 54 | /// 55 | /// Insert one or more Cell(s) items directly into the Sheet. 56 | /// All data can be inserted with this property, but using Tables and Rows add more options to configure style and functionality of generated Sheet. 57 | /// 58 | /// CellBuilder with Build() method at the end of them 59 | IExpectSetComponentsSheetBuilder SetCells(List cellBuilders); 60 | 61 | /// 62 | /// Finish composing Sheet with smaller components i.e. Table(s), Row(s) and Cell(s) 63 | /// 64 | /// 65 | IExpectStyleSheetBuilder NoMoreTablesRowsOrCells(); 66 | } 67 | 68 | public interface IExpectStyleSheetBuilder 69 | { 70 | /// 71 | /// Set Sheet style options like Direction, TextAlign, ColumnsDefaultWith, RowsDefaultHeight and etc. Also Columns style can be configured here 72 | /// 73 | IExpectOtherPropsAndBuildSheetBuilder SetSheetStyle(SheetStyle sheetStyle); 74 | 75 | /// 76 | /// No custom styles for the Sheet, neither for the Sheet itself nor for its Columns 77 | /// 78 | IExpectOtherPropsAndBuildSheetBuilder SheetHasNoCustomStyle(); 79 | } 80 | 81 | public interface IExpectOtherPropsAndBuildSheetBuilder 82 | { 83 | /// 84 | /// Will override the ExcelBuilder AreSheetsLockedByDefault value. Default will inherit 85 | /// 86 | IExpectOtherPropsAndBuildSheetBuilder SetSheetLocked(bool isLocked); 87 | 88 | /// 89 | /// Set Sheet protection status 90 | /// 91 | IExpectProtectionLevelSheetBuilder SetSheetProtected(); 92 | 93 | /// 94 | /// Merged Cells in the Sheet. 95 | /// We prefer merging cells in Table or Row sub-models but in some scenarios this option would be helpful 96 | /// 97 | /// MergeBuilder(s) with Build() method at the end of them 98 | IExpectOtherPropsAndBuildSheetBuilder SetMergedCells(params IMergeBuilder[] mergeBuilders); 99 | 100 | ISheetBuilder Build(); 101 | } 102 | 103 | public interface IExpectProtectionLevelSheetBuilder 104 | { 105 | /// 106 | /// Set Sheet protection level 107 | /// 108 | IExpectOtherPropsAndBuildSheetBuilder SetProtectionLevel(ProtectionLevel protectionLevel); 109 | } -------------------------------------------------------------------------------- /ExcelWizard/Models/EWTable/TableBuilderContracts.cs: -------------------------------------------------------------------------------- 1 | using ExcelWizard.Models.EWCell; 2 | using ExcelWizard.Models.EWMerge; 3 | using ExcelWizard.Models.EWRow; 4 | using System.Collections.Generic; 5 | 6 | namespace ExcelWizard.Models.EWTable; 7 | 8 | public interface ITableBuilder 9 | { 10 | /// 11 | /// Get table Starting Cell Automatically 12 | /// 13 | /// Sometimes Merging Cells definition cause the Table goes beyond boundary of its Cells which is normal. The table actually finish when its Merged Cells finishes 14 | /// 15 | CellLocation GetTableFirstCellLocation(bool considerMergedCells = true); 16 | 17 | /// 18 | /// Get table Ending Cell Automatically 19 | /// 20 | /// Sometimes Merging Cells definition cause the Table goes beyond boundary of its Cells which is normal. The table actually finish when its Merged Cells finishes 21 | /// 22 | CellLocation GetTableLastCellLocation(bool considerMergedCells = true); 23 | 24 | int GetNextHorizontalColumnNumberAfterTable(); 25 | int GetNextVerticalRowNumberAfterTable(); 26 | 27 | /// 28 | /// Get the Table Cell by its location. The Location should be inside Table territory 29 | /// 30 | Cell? GetTableCell(CellLocation cellLocation); 31 | 32 | void ValidateTableInstance(); 33 | } 34 | 35 | public interface IExpectRowsTableBuilder 36 | { 37 | /// 38 | /// Each Table contains one or more Row(s). It is required as Table definition cannot be without Rows. 39 | /// 40 | /// RowBuilder with Build() method at the end 41 | /// RowBuilder(s) with Build() method at the end of them 42 | IExpectMergedCellsStatusInManualProcessTableBuilder SetRows(IRowBuilder rowBuilder, params IRowBuilder[] rowBuilders); 43 | 44 | /// 45 | /// Each Table contains one or more Row(s). It is required as Table definition cannot be without Rows. 46 | /// 47 | /// RowBuilders with Build() method at the end of them 48 | IExpectMergedCellsStatusInManualProcessTableBuilder SetRows(List rowBuilders); 49 | } 50 | 51 | public interface IExpectMergedCellsStatusInManualProcessTableBuilder 52 | { 53 | /// 54 | /// Define of Merged Cells in the current Table. The property is collection, in case 55 | /// we have multiple merged-cells definitions in different locations of the Table. Notice that the Merged Cells 56 | /// should place into the Locations of the current Table, otherwise an error will throw. 57 | /// 58 | /// MergeBuilder with Build() method at the end 59 | /// MergeBuilder(s) with Build() method at the end of them 60 | IExpectStyleTableBuilder SetTableMergedCells(IMergeBuilder mergeBuilder, params IMergeBuilder[] mergeBuilders); 61 | 62 | /// 63 | /// Define of Merged Cells in the current Table. The property is collection, in case 64 | /// we have multiple merged-cells definitions in different locations of the Table. Notice that the Merged Cells 65 | /// should place into the Locations of the current Table, otherwise an error will throw. 66 | /// 67 | /// MergeBuilders with Build() method at the end of them 68 | IExpectStyleTableBuilder SetTableMergedCells(List mergeBuilders); 69 | 70 | /// 71 | /// In case we don't have any merge in the Table 72 | /// 73 | /// 74 | IExpectStyleTableBuilder TableHasNoMerging(); 75 | } 76 | 77 | public interface IExpectStyleTableBuilder 78 | { 79 | /// 80 | /// Set Table Styles e.g. OutsideBorder, etc 81 | /// 82 | IExpectBuildMethodInManualTableBuilder SetTableStyle(TableStyle tableStyle); 83 | 84 | /// 85 | /// No custom styles for the table 86 | /// 87 | IExpectBuildMethodInManualTableBuilder TableHasNoCustomStyle(); 88 | } 89 | 90 | public interface IExpectMergedCellsStatusInModelTableBuilder 91 | { 92 | /// 93 | /// Define of Merged Cells in the current Table. The property is collection, in case 94 | /// we have multiple merged-cells definitions in different locations of the Table. Notice that the Merged Cells 95 | /// should place into the Locations of the current Table, otherwise an error will throw. 96 | /// 97 | /// MergeBuilder with Build() method at the end 98 | /// MergeBuilder(s) with Build() method at the end of them 99 | IExpectBuildMethodInModelTableBuilder SetBoundTableMergedCells(IMergeBuilder mergeBuilder, params IMergeBuilder[] mergeBuilders); 100 | 101 | /// 102 | /// Define of Merged Cells in the current Table. The property is collection, in case 103 | /// we have multiple merged-cells definitions in different locations of the Table. Notice that the Merged Cells 104 | /// should place into the Locations of the current Table, otherwise an error will throw. 105 | /// 106 | /// MergeBuilders with Build() method at the end of them 107 | IExpectBuildMethodInModelTableBuilder SetBoundTableMergedCells(List mergeBuilders); 108 | 109 | /// 110 | /// In case we don't have any merge in the Table 111 | /// 112 | /// 113 | IExpectBuildMethodInModelTableBuilder BoundTableHasNoMerging(); 114 | } 115 | 116 | public interface IExpectBuildMethodInModelTableBuilder 117 | { 118 | ITableBuilder Build(); 119 | } 120 | 121 | public interface IExpectBuildMethodInManualTableBuilder 122 | { 123 | ITableBuilder Build(); 124 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | -------------------------------------------------------------------------------- /ExcelWizard/Models/EWTable/Table.cs: -------------------------------------------------------------------------------- 1 | using ExcelWizard.Models.EWCell; 2 | using ExcelWizard.Models.EWMerge; 3 | using ExcelWizard.Models.EWRow; 4 | using System.Collections.Generic; 5 | using System.ComponentModel.DataAnnotations; 6 | using System.Linq; 7 | 8 | namespace ExcelWizard.Models.EWTable; 9 | 10 | public class Table : ITableBuilder 11 | { 12 | // Props 13 | 14 | /// 15 | /// Each Table contains one or more Row(s). It is required as Table definition cannot be without Rows. 16 | /// 17 | public List TableRows { get; internal set; } = new(); 18 | 19 | /// 20 | /// Set Table Styles e.g. OutsideBorder, etc 21 | /// 22 | public TableStyle TableStyle { get; internal set; } = new(); 23 | 24 | /// 25 | /// Main comment in interface 26 | /// Define of Merged Cells in the current Table. The property is collection, in case 27 | /// we have multiple merged-cells definitions in different locations of the Table. Notice that the Merged Cells 28 | /// should place into the Locations of the current Table, otherwise an error will throw. 29 | /// 30 | public List MergedCellsList { get; internal set; } = new(); 31 | 32 | // Methods 33 | 34 | /// 35 | /// Get table Starting Cell Automatically 36 | /// 37 | /// Sometimes Merging Cells definition cause the Table goes beyond boundary of its Cells which is normal. The table actually finish when its Merged Cells finishes 38 | /// 39 | public CellLocation GetTableFirstCellLocation(bool considerMergedCells = true) 40 | { 41 | var tableRowNumbers = TableRows.Select(r => r.GetRowNumber()).ToList(); 42 | 43 | var startCellRowNumber = tableRowNumbers.Min(); 44 | 45 | var firstCellLocationFromTableWithoutConsideringMergedCells = TableRows.First(r => r.GetRowNumber() == startCellRowNumber).GetRowFirstCellLocation(); 46 | 47 | if (considerMergedCells is false || MergedCellsList.Count == 0) 48 | return firstCellLocationFromTableWithoutConsideringMergedCells; 49 | 50 | // Order priority is based on RowNumber rather than ColumnNumber 51 | 52 | var firstRowOfMergedCells = MergedCellsList.Select(mc => mc.MergedBoundaryLocation.StartCellLocation!.RowNumber).ToList().Min(); 53 | 54 | if (firstRowOfMergedCells >= firstCellLocationFromTableWithoutConsideringMergedCells.RowNumber) 55 | return firstCellLocationFromTableWithoutConsideringMergedCells; 56 | 57 | // Now we know about our target location RowNumber. Lets find its ColumnNumber 58 | // Notice: Cell does not exist in Table location territory 59 | var firstColumnNumberOfMergedCells = MergedCellsList 60 | .Where(mc => mc.MergedBoundaryLocation.StartCellLocation!.RowNumber == firstRowOfMergedCells) 61 | .Select(mc => mc.MergedBoundaryLocation.StartCellLocation!.ColumnNumber) 62 | .Min(); 63 | 64 | return new CellLocation(firstColumnNumberOfMergedCells, firstRowOfMergedCells); 65 | } 66 | 67 | /// 68 | /// Get table Ending Cell Automatically 69 | /// 70 | /// Sometimes Merging Cells definition cause the Table goes beyond boundary of its Cells which is normal. The table actually finish when its Merged Cells finishes 71 | /// 72 | public CellLocation GetTableLastCellLocation(bool considerMergedCells = true) 73 | { 74 | var tableRowNumbers = TableRows.Select(r => r.GetRowNumber()).ToList(); 75 | 76 | var endCellRowNumber = tableRowNumbers.Max(); 77 | 78 | var lastCellLocationFromTableWithoutConsideringMergedCells = TableRows.First(r => r.GetRowNumber() == endCellRowNumber).GetRowLastCellLocation(); 79 | 80 | if (considerMergedCells is false || MergedCellsList.Count == 0) 81 | return lastCellLocationFromTableWithoutConsideringMergedCells; 82 | 83 | // Order priority is based on RowNumber rather than ColumnNumber 84 | 85 | var lastRowOfMergedCells = MergedCellsList.Select(mc => mc.MergedBoundaryLocation.FinishCellLocation!.RowNumber).ToList().Max(); 86 | 87 | if (lastRowOfMergedCells <= lastCellLocationFromTableWithoutConsideringMergedCells.RowNumber) 88 | return lastCellLocationFromTableWithoutConsideringMergedCells; 89 | 90 | // Now we know about our target location RowNumber. Lets find its ColumnNumber 91 | // Notice: Cell does not exist in Table location territory 92 | var lastColumnNumberOfMergedCells = MergedCellsList 93 | .Where(mc => mc.MergedBoundaryLocation.FinishCellLocation!.RowNumber == lastRowOfMergedCells) 94 | .Select(mc => mc.MergedBoundaryLocation.FinishCellLocation!.ColumnNumber) 95 | .Max(); 96 | 97 | return new CellLocation(lastColumnNumberOfMergedCells, lastRowOfMergedCells); 98 | } 99 | 100 | public int GetNextHorizontalColumnNumberAfterTable() 101 | { 102 | var lastTableCell = GetTableLastCellLocation(); 103 | 104 | return lastTableCell.ColumnNumber + 1; 105 | } 106 | 107 | public int GetNextVerticalRowNumberAfterTable() 108 | { 109 | var lastTableCell = GetTableLastCellLocation(); 110 | 111 | return lastTableCell.RowNumber + 1; 112 | } 113 | 114 | /// 115 | /// Get the Table Cell by its location. The Location should be inside Table territory 116 | /// 117 | public Cell? GetTableCell(CellLocation cellLocation) 118 | { 119 | var cellRow = TableRows.FirstOrDefault(r => r.GetRowNumber() == cellLocation.RowNumber); 120 | 121 | return cellRow?.GetRowCellByColumnNumber(cellLocation.ColumnNumber); 122 | } 123 | 124 | // Validations 125 | public void ValidateTableInstance() 126 | { 127 | // Table definition cannot have no Rows 128 | if (TableRows.Count == 0) 129 | throw new ValidationException("Table instance should contain one or more Row(s)"); 130 | 131 | // Check Providing MergedCells Items 132 | if (MergedCellsList.Count != 0) 133 | { 134 | if (MergedCellsList.Any(mc => 135 | mc.MergedBoundaryLocation.StartCellLocation is null || 136 | mc.MergedBoundaryLocation.FinishCellLocation is null)) 137 | { 138 | throw new ValidationException("Table Merged Cells start and end locations are required"); 139 | } 140 | } 141 | 142 | // Check Merged Cells 143 | foreach (var cellsToMerge in MergedCellsList) 144 | { 145 | if (cellsToMerge.MergedBoundaryLocation.StartCellLocation is null || cellsToMerge.MergedBoundaryLocation.FinishCellLocation is null) 146 | throw new ValidationException("Something is not right about MergedCells format. FirstCellLocation and LastCellLocations cannot be null"); 147 | 148 | if (cellsToMerge.MergedBoundaryLocation.StartCellLocation!.RowNumber < GetTableFirstCellLocation().RowNumber) 149 | throw new ValidationException("Something is not right about MergedCells format. The RowNumber of FirstCellLocation cannot be little than TableFirstCellLocation"); 150 | 151 | if (cellsToMerge.MergedBoundaryLocation.StartCellLocation!.ColumnNumber < GetTableFirstCellLocation().ColumnNumber) 152 | throw new ValidationException("Something is not right about MergedCells format. The ColumnNumber of FirstCellLocation cannot be little than TableFirstCellLocation"); 153 | 154 | if (cellsToMerge.MergedBoundaryLocation.FinishCellLocation!.RowNumber > GetTableLastCellLocation().RowNumber) 155 | throw new ValidationException("Something is not right about MergedCells format. The RowNumber of LastCellLocation cannot be greater than TableLastCellLocation"); 156 | 157 | if (cellsToMerge.MergedBoundaryLocation.FinishCellLocation!.ColumnNumber > GetTableLastCellLocation().ColumnNumber) 158 | throw new ValidationException("Something is not right about MergedCells format. The ColumnNumber of LastCellLocation cannot be greater than TableLastCellLocation"); 159 | } 160 | 161 | // Not repetitive Locations 162 | var isAllRowsUnique = TableRows.Select(r => r.GetRowNumber()).Distinct().Count() == TableRows.Count; 163 | 164 | if (isAllRowsUnique is false) 165 | throw new ValidationException("There are some repetitive rows in the Table. Make all rows unique"); 166 | 167 | } 168 | } -------------------------------------------------------------------------------- /samples/BlazorApp/wwwroot/css/open-iconic/font/css/open-iconic-bootstrap.min.css: -------------------------------------------------------------------------------- 1 | @font-face{font-family:Icons;src:url(../fonts/open-iconic.eot);src:url(../fonts/open-iconic.eot?#iconic-sm) format('embedded-opentype'),url(../fonts/open-iconic.woff) format('woff'),url(../fonts/open-iconic.ttf) format('truetype'),url(../fonts/open-iconic.otf) format('opentype'),url(../fonts/open-iconic.svg#iconic-sm) format('svg');font-weight:400;font-style:normal}.oi{position:relative;top:1px;display:inline-block;speak:none;font-family:Icons;font-style:normal;font-weight:400;line-height:1;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.oi:empty:before{width:1em;text-align:center;box-sizing:content-box}.oi.oi-align-center:before{text-align:center}.oi.oi-align-left:before{text-align:left}.oi.oi-align-right:before{text-align:right}.oi.oi-flip-horizontal:before{-webkit-transform:scale(-1,1);-ms-transform:scale(-1,1);transform:scale(-1,1)}.oi.oi-flip-vertical:before{-webkit-transform:scale(1,-1);-ms-transform:scale(-1,1);transform:scale(1,-1)}.oi.oi-flip-horizontal-vertical:before{-webkit-transform:scale(-1,-1);-ms-transform:scale(-1,1);transform:scale(-1,-1)}.oi-account-login:before{content:'\e000'}.oi-account-logout:before{content:'\e001'}.oi-action-redo:before{content:'\e002'}.oi-action-undo:before{content:'\e003'}.oi-align-center:before{content:'\e004'}.oi-align-left:before{content:'\e005'}.oi-align-right:before{content:'\e006'}.oi-aperture:before{content:'\e007'}.oi-arrow-bottom:before{content:'\e008'}.oi-arrow-circle-bottom:before{content:'\e009'}.oi-arrow-circle-left:before{content:'\e00a'}.oi-arrow-circle-right:before{content:'\e00b'}.oi-arrow-circle-top:before{content:'\e00c'}.oi-arrow-left:before{content:'\e00d'}.oi-arrow-right:before{content:'\e00e'}.oi-arrow-thick-bottom:before{content:'\e00f'}.oi-arrow-thick-left:before{content:'\e010'}.oi-arrow-thick-right:before{content:'\e011'}.oi-arrow-thick-top:before{content:'\e012'}.oi-arrow-top:before{content:'\e013'}.oi-audio-spectrum:before{content:'\e014'}.oi-audio:before{content:'\e015'}.oi-badge:before{content:'\e016'}.oi-ban:before{content:'\e017'}.oi-bar-chart:before{content:'\e018'}.oi-basket:before{content:'\e019'}.oi-battery-empty:before{content:'\e01a'}.oi-battery-full:before{content:'\e01b'}.oi-beaker:before{content:'\e01c'}.oi-bell:before{content:'\e01d'}.oi-bluetooth:before{content:'\e01e'}.oi-bold:before{content:'\e01f'}.oi-bolt:before{content:'\e020'}.oi-book:before{content:'\e021'}.oi-bookmark:before{content:'\e022'}.oi-box:before{content:'\e023'}.oi-briefcase:before{content:'\e024'}.oi-british-pound:before{content:'\e025'}.oi-browser:before{content:'\e026'}.oi-brush:before{content:'\e027'}.oi-bug:before{content:'\e028'}.oi-bullhorn:before{content:'\e029'}.oi-calculator:before{content:'\e02a'}.oi-calendar:before{content:'\e02b'}.oi-camera-slr:before{content:'\e02c'}.oi-caret-bottom:before{content:'\e02d'}.oi-caret-left:before{content:'\e02e'}.oi-caret-right:before{content:'\e02f'}.oi-caret-top:before{content:'\e030'}.oi-cart:before{content:'\e031'}.oi-chat:before{content:'\e032'}.oi-check:before{content:'\e033'}.oi-chevron-bottom:before{content:'\e034'}.oi-chevron-left:before{content:'\e035'}.oi-chevron-right:before{content:'\e036'}.oi-chevron-top:before{content:'\e037'}.oi-circle-check:before{content:'\e038'}.oi-circle-x:before{content:'\e039'}.oi-clipboard:before{content:'\e03a'}.oi-clock:before{content:'\e03b'}.oi-cloud-download:before{content:'\e03c'}.oi-cloud-upload:before{content:'\e03d'}.oi-cloud:before{content:'\e03e'}.oi-cloudy:before{content:'\e03f'}.oi-code:before{content:'\e040'}.oi-cog:before{content:'\e041'}.oi-collapse-down:before{content:'\e042'}.oi-collapse-left:before{content:'\e043'}.oi-collapse-right:before{content:'\e044'}.oi-collapse-up:before{content:'\e045'}.oi-command:before{content:'\e046'}.oi-comment-square:before{content:'\e047'}.oi-compass:before{content:'\e048'}.oi-contrast:before{content:'\e049'}.oi-copywriting:before{content:'\e04a'}.oi-credit-card:before{content:'\e04b'}.oi-crop:before{content:'\e04c'}.oi-dashboard:before{content:'\e04d'}.oi-data-transfer-download:before{content:'\e04e'}.oi-data-transfer-upload:before{content:'\e04f'}.oi-delete:before{content:'\e050'}.oi-dial:before{content:'\e051'}.oi-document:before{content:'\e052'}.oi-dollar:before{content:'\e053'}.oi-double-quote-sans-left:before{content:'\e054'}.oi-double-quote-sans-right:before{content:'\e055'}.oi-double-quote-serif-left:before{content:'\e056'}.oi-double-quote-serif-right:before{content:'\e057'}.oi-droplet:before{content:'\e058'}.oi-eject:before{content:'\e059'}.oi-elevator:before{content:'\e05a'}.oi-ellipses:before{content:'\e05b'}.oi-envelope-closed:before{content:'\e05c'}.oi-envelope-open:before{content:'\e05d'}.oi-euro:before{content:'\e05e'}.oi-excerpt:before{content:'\e05f'}.oi-expand-down:before{content:'\e060'}.oi-expand-left:before{content:'\e061'}.oi-expand-right:before{content:'\e062'}.oi-expand-up:before{content:'\e063'}.oi-external-link:before{content:'\e064'}.oi-eye:before{content:'\e065'}.oi-eyedropper:before{content:'\e066'}.oi-file:before{content:'\e067'}.oi-fire:before{content:'\e068'}.oi-flag:before{content:'\e069'}.oi-flash:before{content:'\e06a'}.oi-folder:before{content:'\e06b'}.oi-fork:before{content:'\e06c'}.oi-fullscreen-enter:before{content:'\e06d'}.oi-fullscreen-exit:before{content:'\e06e'}.oi-globe:before{content:'\e06f'}.oi-graph:before{content:'\e070'}.oi-grid-four-up:before{content:'\e071'}.oi-grid-three-up:before{content:'\e072'}.oi-grid-two-up:before{content:'\e073'}.oi-hard-drive:before{content:'\e074'}.oi-header:before{content:'\e075'}.oi-headphones:before{content:'\e076'}.oi-heart:before{content:'\e077'}.oi-home:before{content:'\e078'}.oi-image:before{content:'\e079'}.oi-inbox:before{content:'\e07a'}.oi-infinity:before{content:'\e07b'}.oi-info:before{content:'\e07c'}.oi-italic:before{content:'\e07d'}.oi-justify-center:before{content:'\e07e'}.oi-justify-left:before{content:'\e07f'}.oi-justify-right:before{content:'\e080'}.oi-key:before{content:'\e081'}.oi-laptop:before{content:'\e082'}.oi-layers:before{content:'\e083'}.oi-lightbulb:before{content:'\e084'}.oi-link-broken:before{content:'\e085'}.oi-link-intact:before{content:'\e086'}.oi-list-rich:before{content:'\e087'}.oi-list:before{content:'\e088'}.oi-location:before{content:'\e089'}.oi-lock-locked:before{content:'\e08a'}.oi-lock-unlocked:before{content:'\e08b'}.oi-loop-circular:before{content:'\e08c'}.oi-loop-square:before{content:'\e08d'}.oi-loop:before{content:'\e08e'}.oi-magnifying-glass:before{content:'\e08f'}.oi-map-marker:before{content:'\e090'}.oi-map:before{content:'\e091'}.oi-media-pause:before{content:'\e092'}.oi-media-play:before{content:'\e093'}.oi-media-record:before{content:'\e094'}.oi-media-skip-backward:before{content:'\e095'}.oi-media-skip-forward:before{content:'\e096'}.oi-media-step-backward:before{content:'\e097'}.oi-media-step-forward:before{content:'\e098'}.oi-media-stop:before{content:'\e099'}.oi-medical-cross:before{content:'\e09a'}.oi-menu:before{content:'\e09b'}.oi-microphone:before{content:'\e09c'}.oi-minus:before{content:'\e09d'}.oi-monitor:before{content:'\e09e'}.oi-moon:before{content:'\e09f'}.oi-move:before{content:'\e0a0'}.oi-musical-note:before{content:'\e0a1'}.oi-paperclip:before{content:'\e0a2'}.oi-pencil:before{content:'\e0a3'}.oi-people:before{content:'\e0a4'}.oi-person:before{content:'\e0a5'}.oi-phone:before{content:'\e0a6'}.oi-pie-chart:before{content:'\e0a7'}.oi-pin:before{content:'\e0a8'}.oi-play-circle:before{content:'\e0a9'}.oi-plus:before{content:'\e0aa'}.oi-power-standby:before{content:'\e0ab'}.oi-print:before{content:'\e0ac'}.oi-project:before{content:'\e0ad'}.oi-pulse:before{content:'\e0ae'}.oi-puzzle-piece:before{content:'\e0af'}.oi-question-mark:before{content:'\e0b0'}.oi-rain:before{content:'\e0b1'}.oi-random:before{content:'\e0b2'}.oi-reload:before{content:'\e0b3'}.oi-resize-both:before{content:'\e0b4'}.oi-resize-height:before{content:'\e0b5'}.oi-resize-width:before{content:'\e0b6'}.oi-rss-alt:before{content:'\e0b7'}.oi-rss:before{content:'\e0b8'}.oi-script:before{content:'\e0b9'}.oi-share-boxed:before{content:'\e0ba'}.oi-share:before{content:'\e0bb'}.oi-shield:before{content:'\e0bc'}.oi-signal:before{content:'\e0bd'}.oi-signpost:before{content:'\e0be'}.oi-sort-ascending:before{content:'\e0bf'}.oi-sort-descending:before{content:'\e0c0'}.oi-spreadsheet:before{content:'\e0c1'}.oi-star:before{content:'\e0c2'}.oi-sun:before{content:'\e0c3'}.oi-tablet:before{content:'\e0c4'}.oi-tag:before{content:'\e0c5'}.oi-tags:before{content:'\e0c6'}.oi-target:before{content:'\e0c7'}.oi-task:before{content:'\e0c8'}.oi-terminal:before{content:'\e0c9'}.oi-text:before{content:'\e0ca'}.oi-thumb-down:before{content:'\e0cb'}.oi-thumb-up:before{content:'\e0cc'}.oi-timer:before{content:'\e0cd'}.oi-transfer:before{content:'\e0ce'}.oi-trash:before{content:'\e0cf'}.oi-underline:before{content:'\e0d0'}.oi-vertical-align-bottom:before{content:'\e0d1'}.oi-vertical-align-center:before{content:'\e0d2'}.oi-vertical-align-top:before{content:'\e0d3'}.oi-video:before{content:'\e0d4'}.oi-volume-high:before{content:'\e0d5'}.oi-volume-low:before{content:'\e0d6'}.oi-volume-off:before{content:'\e0d7'}.oi-warning:before{content:'\e0d8'}.oi-wifi:before{content:'\e0d9'}.oi-wrench:before{content:'\e0da'}.oi-x:before{content:'\e0db'}.oi-yen:before{content:'\e0dc'}.oi-zoom-in:before{content:'\e0dd'}.oi-zoom-out:before{content:'\e0de'} -------------------------------------------------------------------------------- /ExcelWizard/Models/EWTable/TableBuilder.cs: -------------------------------------------------------------------------------- 1 | using ExcelWizard.Models.EWCell; 2 | using ExcelWizard.Models.EWMerge; 3 | using ExcelWizard.Models.EWRow; 4 | using ExcelWizard.Models.EWStyles; 5 | using System; 6 | using System.Collections; 7 | using System.Collections.Generic; 8 | using System.Drawing; 9 | using System.Linq; 10 | using System.Reflection; 11 | 12 | namespace ExcelWizard.Models.EWTable; 13 | 14 | public class TableBuilder : IExpectRowsTableBuilder, IExpectMergedCellsStatusInManualProcessTableBuilder, 15 | IExpectStyleTableBuilder, IExpectMergedCellsStatusInModelTableBuilder, 16 | IExpectBuildMethodInModelTableBuilder, IExpectBuildMethodInManualTableBuilder 17 | { 18 | private TableBuilder() { } 19 | 20 | private Table Table { get; set; } = new(); 21 | private bool CanBuild { get; set; } 22 | 23 | /// 24 | /// Automatically construct the Table using a model data and attributes. Attributes to configure are [ExcelTable] and [ExcelTableColumn] 25 | /// 26 | /// The model instance which should be list of an item. The type should be configured by attributes for some styles and other configs 27 | /// The start location of the table. The end point will be calculated dynamically 28 | public static IExpectMergedCellsStatusInModelTableBuilder CreateUsingAModelToBind(object bindingListModel, CellLocation tableStartPoint) 29 | { 30 | var isObjectDataList = bindingListModel is IEnumerable; 31 | 32 | if (isObjectDataList is false) 33 | throw new InvalidOperationException("Provided data for table is not a valid data list"); 34 | 35 | var headerRow = new Row(); 36 | 37 | var dataRows = new List(); 38 | 39 | // Get Header 40 | 41 | bool isHeaderAlreadyCalculated = false; 42 | 43 | bool hasHeader = true; 44 | 45 | List tableHeaderMerges = new(); 46 | 47 | int yLocation = tableStartPoint.RowNumber; 48 | 49 | var borderType = LineStyle.Thin; 50 | 51 | Border outsideBorder = new(); 52 | 53 | Border insideBorder = new(); 54 | 55 | if (bindingListModel is IEnumerable records) 56 | { 57 | foreach (var record in records) 58 | { 59 | // Each record is an entire row of Excel 60 | 61 | var excelTableAttribute = record.GetType().GetCustomAttribute(); 62 | 63 | hasHeader = excelTableAttribute?.HasHeader ?? true; 64 | 65 | var headerOccupyingRowsNo = excelTableAttribute?.HeaderOccupyingRowsNo ?? 1; 66 | 67 | var tableDefaultFontWeight = excelTableAttribute?.FontWeight; 68 | 69 | var tableDefaultFont = new TextFont 70 | { 71 | FontName = excelTableAttribute?.FontName, 72 | FontSize = excelTableAttribute?.FontSize == 0 ? null : excelTableAttribute?.FontSize, 73 | FontColor = Color.FromKnownColor(excelTableAttribute?.FontColor ?? KnownColor.Black), 74 | IsBold = tableDefaultFontWeight == FontWeight.Bold 75 | }; 76 | 77 | outsideBorder = new Border(excelTableAttribute?.OutsideBorderStyle ?? LineStyle.Thin, 78 | Color.FromKnownColor(excelTableAttribute?.OutsideBorderColor ?? KnownColor.LightGray)); 79 | 80 | insideBorder = new Border(excelTableAttribute?.InsideCellsBorderStyle ?? LineStyle.Thin, 81 | Color.FromKnownColor(excelTableAttribute?.InsideCellsBorderColor ?? KnownColor.LightGray)); 82 | 83 | TextAlign tableDefaultTextAlign = excelTableAttribute?.TextAlign ?? TextAlign.Inherit; 84 | 85 | PropertyInfo[] properties = record.GetType().GetProperties(); 86 | 87 | int xLocation = tableStartPoint.ColumnNumber; 88 | 89 | var recordRow = new Row 90 | { 91 | RowStyle = new RowStyle 92 | { 93 | BackgroundColor = Color.FromKnownColor(excelTableAttribute?.DataBackgroundColor ?? KnownColor.Transparent) 94 | } 95 | }; 96 | 97 | // Each loop is a Column 98 | 99 | foreach (var prop in properties) 100 | { 101 | var excelTableColumnAttribute = (ExcelTableColumnAttribute?)prop.GetCustomAttributes(true).FirstOrDefault(x => x is ExcelTableColumnAttribute); 102 | 103 | if (excelTableColumnAttribute?.Ignore ?? false) 104 | continue; 105 | 106 | TextAlign GetCellTextAlign(TextAlign defaultAlign, TextAlign? headerOrDataTextAlign) 107 | { 108 | return headerOrDataTextAlign switch 109 | { 110 | TextAlign.Inherit => defaultAlign, 111 | _ => headerOrDataTextAlign ?? defaultAlign 112 | }; 113 | } 114 | 115 | var finalFont = new TextFont 116 | { 117 | FontName = excelTableColumnAttribute?.FontName ?? tableDefaultFont.FontName, 118 | FontSize = excelTableColumnAttribute?.FontSize is null || excelTableColumnAttribute.FontSize == 0 ? tableDefaultFont.FontSize : excelTableColumnAttribute.FontSize, 119 | FontColor = excelTableColumnAttribute is null || excelTableColumnAttribute.FontColor == KnownColor.Transparent 120 | ? tableDefaultFont.FontColor.Value 121 | : Color.FromKnownColor(excelTableColumnAttribute.FontColor), 122 | IsBold = excelTableColumnAttribute is null || excelTableColumnAttribute.FontWeight == FontWeight.Inherit 123 | ? tableDefaultFont.IsBold 124 | : excelTableColumnAttribute.FontWeight == FontWeight.Bold 125 | }; 126 | 127 | // Header 128 | if (hasHeader && isHeaderAlreadyCalculated is false) 129 | { 130 | var isBold = excelTableColumnAttribute is null || 131 | excelTableColumnAttribute.FontWeight == FontWeight.Inherit 132 | ? tableDefaultFontWeight != FontWeight.Normal 133 | : excelTableColumnAttribute.FontWeight == FontWeight.Bold; 134 | 135 | var headerFontColor = excelTableAttribute?.HeaderFontColor != null ? Color.FromKnownColor(excelTableAttribute.HeaderFontColor) : Color.Empty; 136 | 137 | var headerFontWeight = excelTableAttribute?.HeaderFontWeight != null ? excelTableAttribute.FontWeight : FontWeight.Inherit; 138 | 139 | var headerFont = new TextFont 140 | { 141 | FontColor = headerFontColor == Color.Empty ? finalFont.FontColor : headerFontColor, 142 | FontName = finalFont.FontName, 143 | FontSize = finalFont.FontSize, 144 | IsBold = headerFontWeight == FontWeight.Inherit ? isBold : headerFontWeight == FontWeight.Bold 145 | }; 146 | 147 | Cell headerCell = CellBuilder 148 | .SetLocation(xLocation, yLocation) 149 | .SetValue(excelTableColumnAttribute?.HeaderName ?? prop.Name) 150 | .SetCellStyle(new CellStyle 151 | { 152 | Font = headerFont, 153 | CellTextAlign = GetCellTextAlign(tableDefaultTextAlign, 154 | excelTableColumnAttribute?.HeaderTextAlign) 155 | }) 156 | .SetContentType(CellContentType.Text) 157 | .Build(); 158 | 159 | headerRow.RowCells.Add(headerCell); 160 | 161 | var headerBgColor = excelTableAttribute?.HeaderBackgroundColor != null ? Color.FromKnownColor(excelTableAttribute.HeaderBackgroundColor) : Color.Transparent; 162 | 163 | headerRow.RowStyle.BackgroundColor = headerBgColor; 164 | 165 | headerRow.RowStyle.RowOutsideBorder = new Border { BorderColor = Color.Black, BorderLineStyle = borderType }; 166 | 167 | headerRow.RowStyle.InsideCellsBorder = new Border { BorderColor = Color.Black, BorderLineStyle = borderType }; 168 | 169 | if (headerOccupyingRowsNo > 1) 170 | { 171 | tableHeaderMerges.Add(new MergedCells 172 | { 173 | BackgroundColor = headerBgColor, 174 | 175 | MergedBoundaryLocation = new MergedBoundaryLocation 176 | { 177 | StartCellLocation = new CellLocation(xLocation, tableStartPoint.RowNumber), 178 | FinishCellLocation = new CellLocation(xLocation, tableStartPoint.RowNumber + headerOccupyingRowsNo - 1) 179 | } 180 | }); 181 | } 182 | } 183 | 184 | // Data 185 | int dataYLocation = hasHeader ? yLocation + headerOccupyingRowsNo : yLocation; 186 | 187 | var dataCell = CellBuilder 188 | .SetLocation(xLocation, dataYLocation) 189 | .SetValue(prop.GetValue(record)) 190 | .SetContentType(excelTableColumnAttribute?.DataContentType ?? CellContentType.Text) 191 | .SetCellStyle(new CellStyle 192 | { 193 | Font = finalFont, 194 | CellTextAlign = GetCellTextAlign(tableDefaultTextAlign, 195 | excelTableColumnAttribute?.DataTextAlign) 196 | }) 197 | .Build(); 198 | 199 | recordRow.RowCells.Add(dataCell); 200 | 201 | xLocation++; 202 | } 203 | 204 | dataRows.Add(recordRow); 205 | 206 | yLocation++; 207 | 208 | isHeaderAlreadyCalculated = true; 209 | } 210 | } 211 | 212 | // End of calculations 213 | 214 | List allRows = new List(); 215 | 216 | if (hasHeader) 217 | allRows.Add(headerRow); 218 | 219 | allRows.AddRange(dataRows); 220 | 221 | return new TableBuilder 222 | { 223 | Table = new Table 224 | { 225 | TableRows = allRows, 226 | TableStyle = new TableStyle 227 | { 228 | TableOutsideBorder = outsideBorder, 229 | InsideCellsBorder = insideBorder 230 | }, 231 | MergedCellsList = tableHeaderMerges 232 | } 233 | }; 234 | } 235 | 236 | /// 237 | /// Manually build the Table defining its properties and styles step by step 238 | /// 239 | public static IExpectRowsTableBuilder CreateStepByStepManually() 240 | { 241 | return new TableBuilder 242 | { 243 | Table = new Table() 244 | }; 245 | } 246 | 247 | public IExpectMergedCellsStatusInManualProcessTableBuilder SetRows(IRowBuilder rowBuilder, params IRowBuilder[] rowBuilders) 248 | { 249 | IRowBuilder[] rows = new[] { rowBuilder }.Concat(rowBuilders).ToArray(); 250 | 251 | Table.TableRows = rows.Select(r => (Row)r).ToList(); 252 | 253 | return this; 254 | } 255 | 256 | public IExpectMergedCellsStatusInManualProcessTableBuilder SetRows(List rowBuilders) 257 | { 258 | Table.TableRows = rowBuilders.Select(r => (Row)r).ToList(); 259 | 260 | return this; 261 | } 262 | 263 | public IExpectStyleTableBuilder SetTableMergedCells(IMergeBuilder mergeBuilder, params IMergeBuilder[] mergeBuilders) 264 | { 265 | IMergeBuilder[] merges = new[] { mergeBuilder }.Concat(mergeBuilders).ToArray(); 266 | 267 | CanBuild = true; 268 | 269 | Table.MergedCellsList = merges.Select(m => (MergedCells)m).ToList(); 270 | 271 | return this; 272 | } 273 | 274 | public IExpectStyleTableBuilder SetTableMergedCells(List mergeBuilders) 275 | { 276 | CanBuild = true; 277 | 278 | Table.MergedCellsList = mergeBuilders.Select(m => (MergedCells)m).ToList(); 279 | 280 | return this; 281 | } 282 | 283 | public IExpectStyleTableBuilder TableHasNoMerging() 284 | { 285 | CanBuild = true; 286 | 287 | return this; 288 | } 289 | 290 | public IExpectBuildMethodInManualTableBuilder SetTableStyle(TableStyle tableStyle) 291 | { 292 | Table.TableStyle = tableStyle; 293 | 294 | return this; 295 | } 296 | 297 | public IExpectBuildMethodInManualTableBuilder TableHasNoCustomStyle() 298 | { 299 | return this; 300 | } 301 | 302 | public IExpectBuildMethodInModelTableBuilder SetBoundTableMergedCells(IMergeBuilder mergeBuilder, params IMergeBuilder[] mergeBuilders) 303 | { 304 | IMergeBuilder[] merges = new[] { mergeBuilder }.Concat(mergeBuilders).ToArray(); 305 | 306 | CanBuild = true; 307 | 308 | Table.MergedCellsList = merges.Select(m => (MergedCells)m).ToList(); 309 | 310 | return this; 311 | } 312 | 313 | public IExpectBuildMethodInModelTableBuilder SetBoundTableMergedCells(List mergeBuilders) 314 | { 315 | CanBuild = true; 316 | 317 | Table.MergedCellsList = mergeBuilders.Select(m => (MergedCells)m).ToList(); 318 | 319 | return this; 320 | } 321 | 322 | public IExpectBuildMethodInModelTableBuilder BoundTableHasNoMerging() 323 | { 324 | CanBuild = true; 325 | 326 | return this; 327 | } 328 | 329 | public ITableBuilder Build() 330 | { 331 | if (CanBuild is false) 332 | throw new InvalidOperationException("Cannot build Table because some necessary information not provided"); 333 | 334 | return Table; 335 | } 336 | } -------------------------------------------------------------------------------- /ExcelWizard/Service/FakeBlazorDownloadFileService.cs: -------------------------------------------------------------------------------- 1 | using BlazorDownloadFile; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Text; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | 9 | namespace ExcelWizard.Service; 10 | 11 | public class FakeBlazorDownloadFileService : IBlazorDownloadFileService 12 | { 13 | public ValueTask AddBuffer(string bytesBase64) 14 | { 15 | throw new InvalidOperationException("You can only invoke this method in Blazor context"); 16 | } 17 | 18 | public ValueTask AddBuffer(string bytesBase64, CancellationToken cancellationToken) 19 | { 20 | throw new InvalidOperationException("You can invoke this method in Blazor context"); 21 | } 22 | 23 | public ValueTask AddBuffer(string bytesBase64, TimeSpan timeOut) 24 | { 25 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 26 | } 27 | 28 | public ValueTask AddBuffer(byte[] bytes) 29 | { 30 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 31 | } 32 | 33 | public ValueTask AddBuffer(byte[] bytes, CancellationToken cancellationToken) 34 | { 35 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 36 | } 37 | 38 | public ValueTask AddBuffer(byte[] bytes, TimeSpan timeOut) 39 | { 40 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 41 | } 42 | 43 | public ValueTask AddBuffer(IEnumerable bytes) 44 | { 45 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 46 | } 47 | 48 | public ValueTask AddBuffer(IEnumerable bytes, CancellationToken cancellationToken) 49 | { 50 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 51 | } 52 | 53 | public ValueTask AddBuffer(IEnumerable bytes, TimeSpan timeOut) 54 | { 55 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 56 | } 57 | 58 | public ValueTask AddBuffer(Stream stream) 59 | { 60 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 61 | } 62 | 63 | public ValueTask AddBuffer(Stream stream, CancellationToken cancellationToken) 64 | { 65 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 66 | } 67 | 68 | public ValueTask AddBuffer(Stream stream, CancellationToken streamReadcancellationToken, TimeSpan timeOutJavaScript) 69 | { 70 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 71 | } 72 | 73 | public ValueTask AnyBuffer() 74 | { 75 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 76 | } 77 | 78 | public ValueTask BuffersCount() 79 | { 80 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 81 | } 82 | 83 | public ValueTask ClearBuffers() 84 | { 85 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 86 | } 87 | 88 | public ValueTask DownloadBase64Buffers(string fileName, string contentType = "application/octet-stream") 89 | { 90 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 91 | } 92 | 93 | public ValueTask DownloadBase64Buffers(string fileName, CancellationToken cancellationToken, 94 | string contentType = "application/octet-stream") 95 | { 96 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 97 | } 98 | 99 | public ValueTask DownloadBase64Buffers(string fileName, TimeSpan timeOut, string contentType = "application/octet-stream") 100 | { 101 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 102 | } 103 | 104 | public ValueTask DownloadBinaryBuffers(string fileName, string contentType = "application/octet-stream") 105 | { 106 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 107 | } 108 | 109 | public ValueTask DownloadBinaryBuffers(string fileName, CancellationToken cancellationToken, 110 | string contentType = "application/octet-stream") 111 | { 112 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 113 | } 114 | 115 | public ValueTask DownloadBinaryBuffers(string fileName, TimeSpan timeOut, string contentType = "application/octet-stream") 116 | { 117 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 118 | } 119 | 120 | public ValueTask DownloadFile(string fileName, string bytesBase64, string contentType = "application/octet-stream") 121 | { 122 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 123 | } 124 | 125 | public ValueTask DownloadFile(string fileName, string bytesBase64, CancellationToken cancellationToken, 126 | string contentType = "application/octet-stream") 127 | { 128 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 129 | } 130 | 131 | public ValueTask DownloadFile(string fileName, string bytesBase64, TimeSpan timeOut, 132 | string contentType = "application/octet-stream") 133 | { 134 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 135 | } 136 | 137 | public ValueTask DownloadFile(string fileName, byte[] bytes, string contentType = "application/octet-stream") 138 | { 139 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 140 | } 141 | 142 | public ValueTask DownloadFile(string fileName, byte[] bytes, CancellationToken cancellationToken, 143 | string contentType = "application/octet-stream") 144 | { 145 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 146 | } 147 | 148 | public ValueTask DownloadFile(string fileName, byte[] bytes, TimeSpan timeOut, 149 | string contentType = "application/octet-stream") 150 | { 151 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 152 | } 153 | 154 | public ValueTask DownloadFile(string fileName, IEnumerable bytes, string contentType = "application/octet-stream") 155 | { 156 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 157 | } 158 | 159 | public ValueTask DownloadFile(string fileName, IEnumerable bytes, CancellationToken cancellationToken, 160 | string contentType = "application/octet-stream") 161 | { 162 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 163 | } 164 | 165 | public ValueTask DownloadFile(string fileName, IEnumerable bytes, TimeSpan timeOut, 166 | string contentType = "application/octet-stream") 167 | { 168 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 169 | } 170 | 171 | public ValueTask DownloadFile(string fileName, Stream stream, string contentType = "application/octet-stream") 172 | { 173 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 174 | } 175 | 176 | public ValueTask DownloadFile(string fileName, Stream stream, CancellationToken cancellationTokenBytesRead, 177 | CancellationToken cancellationTokenJavaScriptInterop, string contentType = "application/octet-stream") 178 | { 179 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 180 | } 181 | 182 | public ValueTask DownloadFile(string fileName, Stream stream, CancellationToken cancellationTokenBytesRead, 183 | TimeSpan timeOutJavaScriptInterop, string contentType = "application/octet-stream") 184 | { 185 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 186 | } 187 | 188 | public ValueTask DownloadFileFromText(string fileName, string plainText, Encoding encoding, string contentType = "text/plain", 189 | bool encoderShouldEmitIdentifier = false) 190 | { 191 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 192 | } 193 | 194 | public ValueTask DownloadFileFromText(string fileName, string plainText, Encoding encoding, 195 | CancellationToken cancellationToken, string contentType = "text/plain", bool encoderShouldEmitIdentifier = false) 196 | { 197 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 198 | } 199 | 200 | public ValueTask DownloadFileFromText(string fileName, string plainText, Encoding encoding, TimeSpan timeOut, 201 | string contentType = "text/plain", bool encoderShouldEmitIdentifier = false) 202 | { 203 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 204 | } 205 | 206 | public ValueTask DownloadFile(string fileName, string bytesBase64, int bufferSize = 32768, 207 | string contentType = "application/octet-stream", IProgress? progress = null) 208 | { 209 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 210 | } 211 | 212 | public ValueTask DownloadFile(string fileName, string bytesBase64, CancellationToken cancellationToken, int bufferSize = 32768, 213 | string contentType = "application/octet-stream", IProgress? progress = null) 214 | { 215 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 216 | } 217 | 218 | public ValueTask DownloadFile(string fileName, string bytesBase64, TimeSpan timeOut, int bufferSize = 32768, 219 | string contentType = "application/octet-stream", IProgress? progress = null) 220 | { 221 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 222 | } 223 | 224 | public ValueTask DownloadFile(string fileName, byte[] bytes, int bufferSize = 32768, 225 | string contentType = "application/octet-stream", IProgress? progress = null) 226 | { 227 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 228 | } 229 | 230 | public ValueTask DownloadFile(string fileName, byte[] bytes, CancellationToken cancellationToken, int bufferSize = 32768, 231 | string contentType = "application/octet-stream", IProgress? progress = null) 232 | { 233 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 234 | } 235 | 236 | public ValueTask DownloadFile(string fileName, byte[] bytes, TimeSpan timeOut, int bufferSize = 32768, 237 | string contentType = "application/octet-stream", IProgress? progress = null) 238 | { 239 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 240 | } 241 | 242 | public ValueTask DownloadFile(string fileName, IEnumerable bytes, int bufferSize = 32768, 243 | string contentType = "application/octet-stream", IProgress? progress = null) 244 | { 245 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 246 | } 247 | 248 | public ValueTask DownloadFile(string fileName, IEnumerable bytes, CancellationToken cancellationToken, int bufferSize = 32768, 249 | string contentType = "application/octet-stream", IProgress? progress = null) 250 | { 251 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 252 | } 253 | 254 | public ValueTask DownloadFile(string fileName, IEnumerable bytes, TimeSpan timeOut, int bufferSize = 32768, 255 | string contentType = "application/octet-stream", IProgress? progress = null) 256 | { 257 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 258 | } 259 | 260 | public ValueTask DownloadFile(string fileName, Stream stream, int bufferSize = 32768, 261 | string contentType = "application/octet-stream", IProgress? progress = null) 262 | { 263 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 264 | } 265 | 266 | public ValueTask DownloadFile(string fileName, Stream stream, CancellationToken cancellationTokenBytesRead, 267 | CancellationToken cancellationTokenJavaScriptInterop, int bufferSize = 32768, 268 | string contentType = "application/octet-stream", IProgress? progress = null) 269 | { 270 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 271 | } 272 | 273 | public ValueTask DownloadFile(string fileName, Stream stream, CancellationToken cancellationTokenBytesRead, 274 | TimeSpan timeOutJavaScriptInterop, int bufferSize = 32768, string contentType = "application/octet-stream", 275 | IProgress? progress = null) 276 | { 277 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 278 | } 279 | 280 | public ValueTask DownloadFileFromText(string fileName, string plainText, Encoding encoding, int bufferSize = 32768, 281 | string contentType = "text/plain", IProgress? progress = null, bool encoderShouldEmitIdentifier = false) 282 | { 283 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 284 | } 285 | 286 | public ValueTask DownloadFileFromText(string fileName, string plainText, Encoding encoding, 287 | CancellationToken cancellationToken, int bufferSize = 32768, string contentType = "text/plain", 288 | IProgress? progress = null, bool encoderShouldEmitIdentifier = false) 289 | { 290 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 291 | } 292 | 293 | public ValueTask DownloadFileFromText(string fileName, string plainText, Encoding encoding, TimeSpan timeOut, 294 | int bufferSize = 32768, string contentType = "text/plain", IProgress? progress = null, 295 | bool encoderShouldEmitIdentifier = false) 296 | { 297 | throw new InvalidOperationException("You cannot invoke method in not Blazor context"); 298 | } 299 | } -------------------------------------------------------------------------------- /ExcelWizard/Models/EWExcel/ExcelBuilder.cs: -------------------------------------------------------------------------------- 1 | using ClosedXML.Report.Utils; 2 | using ExcelWizard.Models.EWCell; 3 | using ExcelWizard.Models.EWColumn; 4 | using ExcelWizard.Models.EWGridLayout; 5 | using ExcelWizard.Models.EWRow; 6 | using ExcelWizard.Models.EWSheet; 7 | using ExcelWizard.Models.EWStyles; 8 | using ExcelWizard.Models.EWTable; 9 | using System; 10 | using System.Collections; 11 | using System.Collections.Generic; 12 | using System.Drawing; 13 | using System.Linq; 14 | using System.Reflection; 15 | using System.Text.Json; 16 | 17 | namespace ExcelWizard.Models.EWExcel; 18 | 19 | public class ExcelBuilder : IExpectGeneratingExcelTypeExcelBuilder, IExpectSheetsExcelBuilder 20 | , IExpectStyleExcelBuilder, IExpectOtherPropsAndBuildExcelBuilder, IExpectBuildExcelBuilder 21 | , IExpectGridLayoutExcelBuilder 22 | { 23 | private ExcelBuilder() { } 24 | 25 | private ExcelModel ExcelModel { get; set; } = new(); 26 | private bool CanBuild { get; set; } 27 | 28 | /// 29 | /// Set generated file name 30 | /// 31 | /// Generated file name 32 | public static IExpectGeneratingExcelTypeExcelBuilder SetGeneratedFileName(string? fileName) 33 | { 34 | if (string.IsNullOrWhiteSpace(fileName)) 35 | throw new ArgumentException("Generated file name cannot be empty"); 36 | 37 | return new ExcelBuilder 38 | { 39 | ExcelModel = new ExcelModel 40 | { 41 | GeneratedFileName = fileName 42 | } 43 | }; 44 | } 45 | 46 | public IExpectGridLayoutExcelBuilder CreateGridLayoutExcel() 47 | { 48 | return this; 49 | } 50 | 51 | public IExpectBuildExcelBuilder WithOneSheetUsingModelBinding(object bindingListModel) 52 | { 53 | CanBuild = true; 54 | 55 | var gridLayoutExcelModel = new GridLayoutExcelModel 56 | { 57 | GeneratedFileName = ExcelModel.GeneratedFileName, 58 | 59 | Sheets = new List { new() { DataList = bindingListModel } } 60 | }; 61 | 62 | ExcelModel = ConvertEasyGridExcelBuilderToExcelWizardBuilder(gridLayoutExcelModel); 63 | 64 | return this; 65 | } 66 | 67 | public IExpectStyleExcelBuilder WithMultipleSheetsUsingModelBinding(List listOfBindingListModel) 68 | { 69 | CanBuild = true; 70 | 71 | List gridSheets = listOfBindingListModel.Select(l => new GridExcelSheet { DataList = l }).ToList(); 72 | 73 | GridLayoutExcelModel gridLayoutExcelModel = new GridLayoutExcelModel 74 | { 75 | GeneratedFileName = ExcelModel.GeneratedFileName, 76 | 77 | Sheets = gridSheets 78 | }; 79 | 80 | ExcelModel = ConvertEasyGridExcelBuilderToExcelWizardBuilder(gridLayoutExcelModel); 81 | 82 | return this; 83 | } 84 | 85 | public IExpectStyleExcelBuilder WithMultipleSheetsUsingModelBinding(List bindingSheets) 86 | { 87 | CanBuild = true; 88 | 89 | List gridSheets = bindingSheets.Select(bs => new GridExcelSheet 90 | { SheetName = bs.SheetName, DataList = bs.BindingListModel }).ToList(); 91 | 92 | GridLayoutExcelModel gridLayoutExcelModel = new GridLayoutExcelModel 93 | { 94 | GeneratedFileName = ExcelModel.GeneratedFileName, 95 | 96 | Sheets = gridSheets 97 | }; 98 | 99 | ExcelModel = ConvertEasyGridExcelBuilderToExcelWizardBuilder(gridLayoutExcelModel); 100 | 101 | return this; 102 | } 103 | 104 | public IExpectSheetsExcelBuilder ManuallyWithoutModelBinding() 105 | { 106 | return this; 107 | } 108 | 109 | public IExpectSheetsExcelBuilder CreateComplexLayoutExcel() 110 | { 111 | return this; 112 | } 113 | 114 | public IExpectStyleExcelBuilder SetSheets(ISheetBuilder sheetBuilder, params ISheetBuilder[] sheetBuilders) 115 | { 116 | ISheetBuilder[] sheets = new[] { sheetBuilder }.Concat(sheetBuilders).ToArray(); 117 | 118 | CanBuild = true; 119 | 120 | ExcelModel.Sheets.AddRange(sheets.Select(s => (Sheet)s)); 121 | 122 | return this; 123 | } 124 | 125 | public IExpectOtherPropsAndBuildExcelBuilder SetSheetsDefaultStyle(SheetsDefaultStyle sheetsDefaultStyle) 126 | { 127 | ExcelModel.SheetsDefaultStyle = sheetsDefaultStyle; 128 | 129 | return this; 130 | } 131 | 132 | public IExpectOtherPropsAndBuildExcelBuilder SheetsHaveNoDefaultStyle() 133 | { 134 | return this; 135 | } 136 | 137 | public IExpectBuildExcelBuilder SetDefaultLockedStatus(bool isLockedByDefault) 138 | { 139 | ExcelModel.AreSheetsLockedByDefault = isLockedByDefault; 140 | 141 | return this; 142 | } 143 | 144 | public IExcelBuilder Build() 145 | { 146 | if (CanBuild is false) 147 | throw new InvalidOperationException("Cannot build Excel model because some necessary information are not provided"); 148 | 149 | return ExcelModel; 150 | } 151 | 152 | 153 | private ExcelModel ConvertEasyGridExcelBuilderToExcelWizardBuilder(GridLayoutExcelModel gridLayoutExcelModel) 154 | { 155 | var excelWizardBuilder = new ExcelModel(); 156 | 157 | if (gridLayoutExcelModel.GeneratedFileName.IsNullOrWhiteSpace() is false) 158 | excelWizardBuilder.GeneratedFileName = gridLayoutExcelModel.GeneratedFileName; 159 | 160 | foreach (var gridExcelSheet in gridLayoutExcelModel.Sheets) 161 | { 162 | gridExcelSheet.ValidateGridExcelSheetInstance(); 163 | 164 | if (gridExcelSheet.DataList is IEnumerable records) 165 | { 166 | var headerRow = new Row(); 167 | 168 | var dataRows = new List(); 169 | 170 | // Get Header 171 | 172 | bool isHeaderAlreadyCalculated = false; 173 | 174 | int yLocation = 1; 175 | 176 | string? sheetName = null; 177 | 178 | var borderType = LineStyle.Thin; 179 | 180 | var borderColor = Color.FromKnownColor(KnownColor.LightGray); 181 | 182 | var columnsStyle = new List(); 183 | 184 | SheetDirection sheetDirection = SheetDirection.LeftToRight; 185 | 186 | bool isSheetLocked = false; 187 | 188 | bool isSheetProtected = false; 189 | 190 | ProtectionLevel sheetProtectionLevel = new(); 191 | 192 | foreach (var record in records) 193 | { 194 | // Each record is an entire row of Excel 195 | 196 | var excelSheetAttribute = record.GetType().GetCustomAttribute(); 197 | 198 | sheetName = string.IsNullOrWhiteSpace(gridExcelSheet.SheetName) 199 | ? excelSheetAttribute?.SheetName 200 | : gridExcelSheet.SheetName; 201 | 202 | sheetDirection = excelSheetAttribute?.SheetDirection ?? SheetDirection.LeftToRight; 203 | 204 | var defaultFontWeight = excelSheetAttribute?.FontWeight; 205 | 206 | var defaultFont = new TextFont 207 | { 208 | FontName = excelSheetAttribute?.FontName, 209 | FontSize = excelSheetAttribute?.FontSize == 0 ? null : excelSheetAttribute?.FontSize, 210 | FontColor = Color.FromKnownColor(excelSheetAttribute?.FontColor ?? KnownColor.Black), 211 | IsBold = defaultFontWeight == FontWeight.Bold 212 | }; 213 | 214 | isSheetLocked = excelSheetAttribute?.IsSheetLocked ?? false; 215 | 216 | var isSheetHardProtected = excelSheetAttribute?.IsSheetHardProtected ?? false; 217 | 218 | if (isSheetHardProtected) 219 | { 220 | isSheetProtected = true; 221 | sheetProtectionLevel.HardProtect = true; 222 | } 223 | 224 | borderType = excelSheetAttribute?.BorderType ?? LineStyle.Thin; 225 | borderColor = Color.FromKnownColor(excelSheetAttribute?.BorderColor ?? KnownColor.LightGray); 226 | 227 | var defaultTextAlign = excelSheetAttribute?.DefaultTextAlign ?? TextAlign.Center; 228 | 229 | PropertyInfo[] properties = record.GetType().GetProperties(); 230 | 231 | int xLocation = 1; 232 | 233 | var recordRow = new Row 234 | { 235 | RowStyle = new RowStyle 236 | { 237 | RowHeight = excelSheetAttribute?.DataRowHeight == 0 ? null : excelSheetAttribute?.DataRowHeight, 238 | BackgroundColor = excelSheetAttribute?.DataBackgroundColor != null ? Color.FromKnownColor(excelSheetAttribute.DataBackgroundColor) : Color.Transparent 239 | } 240 | }; 241 | 242 | // Each loop is a Column 243 | foreach (var prop in properties) 244 | { 245 | var excelSheetColumnAttribute = (ExcelSheetColumnAttribute?)prop.GetCustomAttributes(true).FirstOrDefault(x => x is ExcelSheetColumnAttribute); 246 | 247 | if (excelSheetColumnAttribute?.Ignore ?? false) 248 | continue; 249 | 250 | TextAlign GetCellTextAlign(TextAlign defaultAlign, TextAlign? headerOrDataTextAlign) 251 | { 252 | return headerOrDataTextAlign switch 253 | { 254 | TextAlign.Inherit => defaultAlign, 255 | _ => headerOrDataTextAlign ?? defaultAlign 256 | }; 257 | } 258 | 259 | var finalFont = new TextFont 260 | { 261 | FontName = excelSheetColumnAttribute?.FontName ?? defaultFont.FontName, 262 | FontSize = excelSheetColumnAttribute?.FontSize is null || excelSheetColumnAttribute.FontSize == 0 ? defaultFont.FontSize : excelSheetColumnAttribute.FontSize, 263 | FontColor = excelSheetColumnAttribute is null || excelSheetColumnAttribute.FontColor == KnownColor.Transparent 264 | ? defaultFont.FontColor.Value 265 | : Color.FromKnownColor(excelSheetColumnAttribute.FontColor), 266 | IsBold = excelSheetColumnAttribute is null || excelSheetColumnAttribute.FontWeight == FontWeight.Inherit 267 | ? defaultFont.IsBold 268 | : excelSheetColumnAttribute.FontWeight == FontWeight.Bold 269 | }; 270 | 271 | // Header 272 | if (isHeaderAlreadyCalculated is false) 273 | { 274 | var headerFont = JsonSerializer.Deserialize(JsonSerializer.Serialize(finalFont)); 275 | 276 | headerFont.IsBold = excelSheetColumnAttribute is null || excelSheetColumnAttribute.FontWeight == FontWeight.Inherit 277 | ? defaultFontWeight != FontWeight.Normal 278 | : excelSheetColumnAttribute.FontWeight == FontWeight.Bold; 279 | 280 | Cell headerCell = CellBuilder 281 | .SetLocation(xLocation, yLocation) 282 | .SetValue(excelSheetColumnAttribute?.HeaderName ?? prop.Name) 283 | .SetCellStyle(new CellStyle 284 | { 285 | Font = headerFont, 286 | CellTextAlign = GetCellTextAlign(defaultTextAlign, 287 | excelSheetColumnAttribute?.HeaderTextAlign) 288 | }) 289 | .SetContentType(CellContentType.Text) 290 | .Build(); 291 | 292 | headerRow.RowCells.Add(headerCell); 293 | 294 | headerRow.RowStyle.RowHeight = excelSheetAttribute?.HeaderHeight == 0 ? null : excelSheetAttribute?.HeaderHeight; 295 | 296 | headerRow.RowStyle.BackgroundColor = excelSheetAttribute?.HeaderBackgroundColor != null ? Color.FromKnownColor(excelSheetAttribute.HeaderBackgroundColor) : Color.Transparent; 297 | 298 | headerRow.RowStyle.RowOutsideBorder = new Border { BorderColor = borderColor, BorderLineStyle = borderType }; 299 | 300 | headerRow.RowStyle.InsideCellsBorder = new Border { BorderColor = borderColor, BorderLineStyle = borderType }; 301 | 302 | // Calculate Columns style 303 | columnsStyle.Add(new ColumnStyle(xLocation) 304 | { 305 | ColumnWidth = new ColumnWidth 306 | { 307 | Width = excelSheetColumnAttribute?.ColumnWidth == 0 ? null : excelSheetColumnAttribute?.ColumnWidth, 308 | WidthCalculationType = excelSheetColumnAttribute is null || excelSheetColumnAttribute.ColumnWidth == 0 ? ColumnWidthCalculationType.AdjustToContents : ColumnWidthCalculationType.ExplicitValue 309 | } 310 | }); 311 | } 312 | 313 | // Data 314 | var dataCell = CellBuilder 315 | .SetLocation(xLocation, yLocation + 1) 316 | .SetValue(prop.GetValue(record)) 317 | .SetContentType(excelSheetColumnAttribute?.ExcelDataContentType ?? CellContentType.Text) 318 | .SetCellStyle(new CellStyle 319 | { 320 | Font = finalFont, 321 | CellTextAlign = GetCellTextAlign(defaultTextAlign, 322 | excelSheetColumnAttribute?.DataTextAlign) 323 | }) 324 | .Build(); 325 | 326 | recordRow.RowCells.Add(dataCell); 327 | 328 | xLocation++; 329 | } 330 | 331 | dataRows.Add(recordRow); 332 | 333 | yLocation++; 334 | 335 | isHeaderAlreadyCalculated = true; 336 | } 337 | 338 | excelWizardBuilder.Sheets.Add(new Sheet 339 | { 340 | SheetName = sheetName, 341 | 342 | SheetStyle = new SheetStyle { SheetDirection = sheetDirection, ColumnsStyle = columnsStyle }, 343 | 344 | IsSheetLocked = isSheetLocked, 345 | 346 | IsSheetProtected = isSheetProtected, 347 | 348 | SheetProtectionLevel = sheetProtectionLevel, 349 | 350 | // Header Row 351 | SheetRows = new List { headerRow }, 352 | 353 | // Table Data 354 | SheetTables = new List
355 | { 356 | new() 357 | { 358 | TableRows = dataRows, 359 | TableStyle= new TableStyle 360 | { 361 | TableOutsideBorder = new Border { BorderLineStyle = borderType, BorderColor = borderColor }, 362 | InsideCellsBorder = new Border { BorderLineStyle = borderType, BorderColor = borderColor } 363 | } 364 | } 365 | } 366 | }); 367 | } 368 | else 369 | { 370 | throw new Exception("GridExcelSheet object should be IEnumerable"); 371 | } 372 | } 373 | 374 | return excelWizardBuilder; 375 | } 376 | } --------------------------------------------------------------------------------