public void Build_FromDataReader_Correct() { VerticalReportSchemaBuilder <IDataReader> builder = new VerticalReportSchemaBuilder <IDataReader>(); builder.AddColumn("Name", x => x.GetString(0)); builder.AddColumn("Age", x => x.GetInt32(1)); DataTable dataTable = new DataTable(); dataTable.Columns.AddRange(new[] { new DataColumn("Name", typeof(string)), new DataColumn("Age", typeof(int)), }); dataTable.Rows.Add("John", 23); dataTable.Rows.Add("Jane", 22); IDataReader dataReader = new DataTableReader(dataTable); IReportTable <ReportCell> reportTable = builder.BuildSchema().BuildReportTable(dataReader); ReportCell[][] cells = this.GetCellsAsArray(reportTable.Rows); cells[0][0].GetValue <string>().Should().Be("John"); cells[0][1].GetValue <int>().Should().Be(23); cells[1][0].GetValue <string>().Should().Be("Jane"); cells[1][1].GetValue <int>().Should().Be(22); }
public void Build_TextValue_CorrectCells() { IReportTable <ReportCell> table = new ReportTable <ReportCell>() { HeaderRows = new List <IEnumerable <ReportCell> >() { new ReportCell[] { new ReportCell <string>("Value"), }, }, Rows = new List <IEnumerable <ReportCell> >() { new ReportCell[] { new ReportCell <string>("Test"), }, }, }; ReportConverter <HtmlReportCell> converter = new ReportConverter <HtmlReportCell>(Enumerable.Empty <IPropertyHandler <HtmlReportCell> >()); IReportTable <HtmlReportCell> htmlReportTable = converter.Convert(table); HtmlReportCell[][] headerCells = this.GetHeaderCellsAsArray(htmlReportTable); headerCells.Should().HaveCount(1); headerCells[0][0].GetValue <string>().Should().Be("Value"); headerCells[0][0].ColumnSpan.Should().Be(1); headerCells[0][0].RowSpan.Should().Be(1); HtmlReportCell[][] cells = this.GetBodyCellsAsArray(htmlReportTable); cells.Should().HaveCount(1); cells[0][0].GetValue <string>().Should().Be("Test"); cells[0][0].ColumnSpan.Should().Be(1); cells[0][0].RowSpan.Should().Be(1); }
protected virtual ExcelAddress WriteBody(ExcelWorksheet worksheet, IReportTable <ExcelReportCell> table, int startRow, int startColumn) { int maxColumn = startColumn; int row = startRow; foreach (IEnumerable <ExcelReportCell> bodyRow in table.Rows) { int column = startColumn; foreach (ExcelReportCell cell in bodyRow) { if (cell != null) { this.WriteCell(worksheet.Cells[row, column], cell); } column++; } if (column > maxColumn) { maxColumn = column; } row++; } row--; maxColumn--; this.ApplyColumnFormat(worksheet, startRow, row); return(row >= startRow ? new ExcelAddress(startRow, startColumn, row, maxColumn) : null); }
public void Build_DateTimeColumnWithFormat_CorrectDisplayValue() { VerticalReportSchemaBuilder <DateTime> reportBuilder = new VerticalReportSchemaBuilder <DateTime>(); reportBuilder.AddColumn("The Date", d => d); // .SetValueFormatter(new DateTimeValueFormatter("MM/dd/yyyy")); reportBuilder.AddColumn("Next Day", d => d.AddDays(1)); // .SetValueFormatter(new DateTimeValueFormatter("MM/dd/yyyy")); IReportTable <ReportCell> table = reportBuilder.BuildSchema().BuildReportTable(new[] { new DateTime(2020, 10, 24, 20, 25, 00), }); ReportCell[][] headerCells = this.GetCellsAsArray(table.HeaderRows); headerCells.Should().HaveCount(1); headerCells[0][0].Value.Should().Be("The Date"); headerCells[0][0].ValueType.Should().Be(typeof(string)); headerCells[0][1].Value.Should().Be("Next Day"); headerCells[0][1].ValueType.Should().Be(typeof(string)); ReportCell[][] cells = this.GetCellsAsArray(table.Rows); cells.Should().HaveCount(1); cells[0][0].Value.Should().Be("10/24/2020"); cells[0][0].ValueType.Should().Be(typeof(DateTime)); cells[0][1].Value.Should().Be("10/25/2020"); cells[0][1].ValueType.Should().Be(typeof(DateTime)); }
public void BuildVerticalReport_GlobalPropertiesWhenOverwrittenForHeader_Applied() { AttributeBasedBuilder helper = new AttributeBasedBuilder( Mocks.ServiceProvider, new[] { new CommonAttributeHandler() }); IReportSchema <WithOverwrittenForHeaderGlobalProperties> schema = helper.BuildSchema <WithOverwrittenForHeaderGlobalProperties>(); IReportTable <ReportCell> reportTable = schema.BuildReportTable( new[] { new WithOverwrittenForHeaderGlobalProperties() { Id = 1 }, }); ReportCell[][] headerCells = this.GetCellsAsArray(reportTable.HeaderRows); headerCells[0][0].Properties.Should().HaveCount(1) .And.ContainSingle(p => p is AlignmentProperty && ((AlignmentProperty)p).Alignment == Alignment.Right); ReportCell[][] cells = this.GetCellsAsArray(reportTable.Rows); cells[0][0].Properties.Should().HaveCount(1) .And.ContainSingle(p => p is AlignmentProperty && ((AlignmentProperty)p).Alignment == Alignment.Center); }
protected virtual async Task WriteBodyAsync(IReportTable <HtmlReportCell> reportTable) { bool isBodyStarted = false; foreach (IEnumerable <HtmlReportCell> row in reportTable.Rows) { if (!isBodyStarted) { await this.BeginBodyAsync(); isBodyStarted = true; } await this.BeginRowAsync(); foreach (HtmlReportCell cell in row.Where(c => c != null)) { await this.WriteTextAsync(this.stringCellWriter.WriteBodyCell(cell)); } await this.EndRowAsync(); } if (isBodyStarted) { await this.EndBodyAsync(); } }
private Stream WriteExcelReportToStream(IReportTable <ExcelReportCell> reportTable) { EpplusWriter writer = new EpplusWriter(); writer.AddFormatter(new ExcelIndentationPropertyFormatter()); return(writer.WriteToStream(reportTable)); }
public async Task <IActionResult> OrdersDetails() { IReportTable <ReportCell> report = this.reportService.GetReport(await this.productService.GetOrdersDetailsAsync(50)); IReportTable <HtmlReportCell> htmlTable = this.htmlConverter.Convert(report); string reportHtml = await this.stringWriter.WriteToStringAsync(htmlTable); return(this.View(new ReportViewModel(reportHtml))); }
public void Build_TwoRows_CorrectCells() { HorizontalReportSchemaBuilder <(string FirstName, string LastName)> reportBuilder = new HorizontalReportSchemaBuilder <(string FirstName, string LastName)>(); reportBuilder.AddRow("First name", x => x.FirstName); reportBuilder.AddRow("Last name", x => x.LastName); IReportTable <ReportCell> table = reportBuilder.BuildSchema().BuildReportTable(new[]
public void Build_NoRows_HasHeader() { VerticalReportSchemaBuilder <(string FirstName, string LastName)> reportBuilder = new VerticalReportSchemaBuilder <(string FirstName, string LastName)>(); reportBuilder.AddColumn("First name", x => x.FirstName); reportBuilder.AddColumn("Last name", x => x.LastName); IReportTable <ReportCell> table = reportBuilder.BuildSchema().BuildReportTable(new (string, string)[] { });
public void WriteToFile(IReportTable <ExcelReportCell> table, string fileName) { using ExcelPackage excelPackage = new ExcelPackage(new FileInfo(fileName)); this.WriteReport(table, excelPackage); excelPackage.Save(); }
private IReportTable <ExcelReportCell> ConvertToExcel(IReportTable <ReportCell> reportTable) { ReportConverter <ExcelReportCell> excelConverter = new ReportConverter <ExcelReportCell>(new IPropertyHandler <ExcelReportCell>[] { }); return(excelConverter.Convert(reportTable)); }
private Stream WriteExcelReportToStream(IReportTable <ExcelReportCell> reportTable) { EpplusWriter writer = new EpplusWriter(); writer.AddFormatter(new ConditionalFormattingThreeColorScaleFormatter()); return(writer.WriteToStream(reportTable)); }
public async Task <string> WriteToStringAsync(IReportTable <HtmlReportCell> reportTable) { this.stringBuilder = new StringBuilder(); this.writeTextAsync = this.WriteToStringBuilderAsync; await this.WriteReportAsync(reportTable); return(this.stringBuilder.ToString()); }
public void Build_TwoColumnsTwoHeaderRowsByColumnName_CorrectCells() { VerticalReportSchemaBuilder <(string Name, int Age)> reportBuilder = new VerticalReportSchemaBuilder <(string Name, int Age)>(); reportBuilder.AddColumn("Name", x => x.Name); reportBuilder.AddColumn("Age", x => x.Age); reportBuilder.AddComplexHeader(0, "Personal Info", "Name", "Age"); IReportTable <ReportCell> table = reportBuilder.BuildSchema().BuildReportTable(new[]
private IReportTable <ExcelReportCell> ConvertToExcel(IReportTable <ReportCell> reportTable) { ReportConverter <ExcelReportCell> excelConverter = new ReportConverter <ExcelReportCell>(new[] { new HeatmapPropertyExcelHandler(), }); return(excelConverter.Convert(reportTable)); }
public async Task WriteToFileAsync(IReportTable <HtmlReportCell> reportTable, string fileName) { this.fileStream = File.OpenWrite(fileName); this.writeTextAsync = this.WriteToFileAsync; await this.WriteReportAsync(reportTable); this.fileStream.Close(); }
public IActionResult Download() { IReportTable <ReportCell> reportTable = this.BuildReport(); IReportTable <ExcelReportCell> excelReportTable = this.ConvertToExcel(reportTable); Stream excelStream = this.WriteExcelReportToStream(excelReportTable); return(this.File(excelStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Heatmap.xlsx")); }
private IReportTable <HtmlReportCell> ConvertToHtml(IReportTable <ReportCell> reportTable) { ReportConverter <HtmlReportCell> htmlConverter = new ReportConverter <HtmlReportCell>(new[] { new HeatmapPropertyHtmlHandler(), }); return(htmlConverter.Convert(reportTable)); }
public IReportTable <TResultReportCell> Convert(IReportTable <ReportCell> table) { return(new ReportTable <TResultReportCell> { Properties = table.Properties, HeaderRows = this.ConvertHeader(table), Rows = this.ConvertBody(table), }); }
public async Task <IActionResult> DownloadUsers() { IReportTable <ReportCell> report = this.reportService.GetReport(await this.userService.GetActiveUsersAsync()); IReportTable <ExcelReportCell> excelTable = this.excelConverter.Convert(report); Stream excelStream = this.excelWriter.WriteToStream(excelTable); return(this.File(excelStream, ExcelMimeType, "Users.xlsx")); }
private IReportTable <HtmlReportCell> ConvertToHtml(IReportTable <ReportCell> reportTable) { ReportConverter <HtmlReportCell> htmlConverter = new ReportConverter <HtmlReportCell>(new IPropertyHandler <HtmlReportCell>[] { new AlignmentPropertyHtmlHandler(), new ColorPropertyHtmlHandler(), }); return(htmlConverter.Convert(reportTable)); }
protected virtual async Task WriteReportAsync(IReportTable <HtmlReportCell> reportTable) { await this.BeginTableAsync(); await this.WriteHeaderAsync(reportTable); await this.WriteBodyAsync(reportTable); await this.EndTableAsync(); }
private IReportTable <ExcelReportCell> ConvertToExcel(IReportTable <ReportCell> reportTable) { ReportConverter <ExcelReportCell> excelConverter = new ReportConverter <ExcelReportCell>(new IPropertyHandler <ExcelReportCell>[] { new AlignmentPropertyExcelHandler(), new ColorPropertyExcelHandler(), }); return(excelConverter.Convert(reportTable)); }
public async Task <IActionResult> Index() { IReportTable <ReportCell> reportTable = this.BuildReport(); IReportTable <HtmlReportCell> htmlReportTable = this.ConvertToHtml(reportTable); string tableHtml = await this.WriteReportToString(htmlReportTable); return(this.View(new ViewModel() { ReportTableHtml = tableHtml })); }
public async Task <IActionResult> DownloadOrdersDetails() { IReportTable <ReportCell> report = this.reportService.GetReport(await this.productService.GetOrdersDetailsAsync()); IReportTable <ExcelReportCell> excelTable = this.excelConverter.Convert(report); Stream stream = this.excelWriter.WriteToStream(excelTable); return(new FileStreamResult(stream, ExcelMimeType) { FileDownloadName = "OrdersDetails.xlsx" }); }
private IReportTable <ReportCell> BuildReport() { VerticalReportSchemaBuilder <Entity> reportBuilder = new VerticalReportSchemaBuilder <Entity>(); reportBuilder.AddColumn("Name", e => e.Name); reportBuilder.AddColumn("Last Score", e => e.LastScore); reportBuilder.AddColumn("Score", e => e.Score); IReportTable <ReportCell> reportTable = reportBuilder.BuildSchema().BuildReportTable(this.GetData()); return(reportTable); }
public void BuildVerticalReport_PropertiesWithoutAttribute_Ignored() { AttributeBasedBuilder builderHelper = new AttributeBasedBuilder(Mocks.ServiceProvider); IReportSchema <SomePropertiesWithoutAttribute> schema = builderHelper.BuildSchema <SomePropertiesWithoutAttribute>(); IReportTable <ReportCell> reportTable = schema.BuildReportTable(Enumerable.Empty <SomePropertiesWithoutAttribute>()); ReportCell[][] headerCells = this.GetCellsAsArray(reportTable.HeaderRows); headerCells.Should().HaveCount(1); headerCells[0].Should().HaveCount(1); headerCells[0][0].GetValue <string>().Should().Be("Name"); }
public void BuildVerticalReport_SeveralProperties_CorrectOrder() { AttributeBasedBuilder builderHelper = new AttributeBasedBuilder(Mocks.ServiceProvider); IReportSchema <SeveralPropertiesClass> schema = builderHelper.BuildSchema <SeveralPropertiesClass>(); IReportTable <ReportCell> reportTable = schema.BuildReportTable(Enumerable.Empty <SeveralPropertiesClass>()); ReportCell[][] headerCells = this.GetCellsAsArray(reportTable.HeaderRows); headerCells.Should().HaveCount(1); headerCells[0].Should().HaveCount(2); headerCells[0][0].GetValue <string>().Should().Be("ID"); headerCells[0][1].GetValue <string>().Should().Be("Name"); }
private IReportTable <ReportCell> BuildReport() { HighlightCellProcessor highlightCellProcessor = new HighlightCellProcessor(); VerticalReportSchemaBuilder <Entity> reportBuilder = new VerticalReportSchemaBuilder <Entity>(); reportBuilder.AddColumn("Name", e => e.Name).AddProcessors(highlightCellProcessor); reportBuilder.AddColumn("Score", e => e.Score).AddProcessors(highlightCellProcessor); IReportTable <ReportCell> reportTable = reportBuilder.BuildSchema().BuildReportTable(this.GetData()); return(reportTable); }