Skip to content

Commit

Permalink
Fill object 0.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
tiorac committed Dec 13, 2023
1 parent 0bc9112 commit 61dfc9b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 25 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ dotnet add package BlackDigital.Report
ReportGenerator.Spreadsheet()
.AddSheet("First")
.AddTable("Data")
.AddHeader(new List<string>() { "Name", "Number", "ObjDate", "Time" })
.AddBody(list)
.Fill(list)
.BuildAsync(@"test.xlsx");
```

Expand Down Expand Up @@ -188,8 +187,8 @@ The return type of BuildAsync has also changed. Instead of returning just a byte
☑️ Spreadsheet cell configurations. (0.5.0)
☑️ ReportFile class as build return. (0.5.0)
☑️ .NET7 and .NET8 support (0.5.0)
️ Header Globalization. (removed on refactory 0.5.0)
️ Use DisplayAttribute to get name of columns and properties that should be generated.
️ Header Globalization. (0.5.1)
️ Use DisplayAttribute to get name of columns and properties that should be generated. (0.5.1)
◼️ Cells with formulas.
◼️ Cell value event.
◼️ Tables footers.
Expand Down
16 changes: 9 additions & 7 deletions examples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
list.Add(new("Line <1> \r\n &A", 10, DateTime.Today, TimeSpan.FromHours(3), DateOnly.FromDateTime(DateTime.Today), new(3, 0)));
list.Add(new("Line <2> \r\n &B", -10, DateTime.Now, TimeSpan.FromMinutes(12), DateOnly.FromDateTime(DateTime.Today), new(5, 30)));
list.Add(new("Line <3> \n\r &C", 10.6d, DateTime.UtcNow, TimeSpan.FromMinutes(45).Add(TimeSpan.FromSeconds(31)), DateOnly.FromDateTime(DateTime.Today), new(17, 45)));
list.Add(new(null, 10.6d, DateTime.UtcNow, TimeSpan.FromMinutes(45).Add(TimeSpan.FromSeconds(31)), DateOnly.FromDateTime(DateTime.Today), new(17, 45)));

List<string> headers = new()
{
Expand Down Expand Up @@ -73,7 +74,8 @@
//System.Text.Json.Serialization.JsonStringEnumConverter
//string a;

var task = ReportGenerator.Spreadsheet()
/*var task = ReportGenerator.Spreadsheet()
.SetCompany("BlackDigital")
.SetApplication("BlackDigital Report")
.SetManager("TioRAC Lab")
Expand Down Expand Up @@ -106,24 +108,24 @@
task.Wait();
return;
return;*/

/*task = ReportGenerator.Spreadsheet()
var task = ReportGenerator.Spreadsheet()
.SetCompany("BlackDigital")
.SetResourceManager(Texts.ResourceManager)
.SetFormatProvider(new CultureInfo("pt"))
.AddSheet("First")
.AddTable("Data")
.FillObject(list)
.Spreadsheet()
.Fill(list)
/*.Spreadsheet()
.AddSheet("Second")
.AddValue("My text header")
.AddTable("Data2", "B3")
.AddHeader(headers)
.Fill(list2)
.Sheet()
.AddTable("Data3", "g4")
.FillObject(list)
.BuildAsync("test-pt.xlsx");*/
.FillObject(list)*/
.BuildAsync("D:\\Teste\\temp\\test-default.xlsx");

task.Wait();
6 changes: 3 additions & 3 deletions src/BlackDigital.Report.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0;net5.0</TargetFrameworks>
<Nullable>enable</Nullable>
<AssemblyVersion>0.5.0</AssemblyVersion>
<FileVersion>0.5.0</FileVersion>
<AssemblyVersion>0.5.1</AssemblyVersion>
<FileVersion>0.5.1</FileVersion>
<PackageReadmeFile>README.md</PackageReadmeFile>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>$(VersionPrefix)0.5.0</Version>
<Version>$(VersionPrefix)0.5.1</Version>
<Description>Simple report generator using OpenXML. Currently it is only generating reports in spreadsheets.</Description>
<PackageProjectUrl>https://github.com/blackdigital-br/BlackReport</PackageProjectUrl>
<RepositoryUrl>https://github.com/blackdigital-br/BlackReport</RepositoryUrl>
Expand Down
20 changes: 9 additions & 11 deletions src/ReportHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
using System.Reflection;
using System.Globalization;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using BlackDigital.Report.Sources;

using System.ComponentModel.DataAnnotations;

namespace BlackDigital.Report
{
internal static class ReportHelper
{
internal static EnumerableReportSource GetObjectHeader<T>(ResourceManager? resource, CultureInfo? culture)
internal static ReportSource GetObjectHeader<T>(ResourceManager? resource, CultureInfo? culture)
{
var properties = GetPropertiesAndAttributes<T>();
var header = properties.Select(p =>
Expand All @@ -28,18 +27,15 @@ internal static EnumerableReportSource GetObjectHeader<T>(ResourceManager? resou
}
return columnName;
}).AsEnumerable();
}).ToList();

List<IEnumerable<string>> headerDataset = new();
headerDataset.Add(header);

var source = new EnumerableReportSource();
source.Load(headerDataset);
var source = new ListReportSource();
source.Load(header);

return source;
}

internal static List<List<object>> ObjectToData<T>(IEnumerable<T> data)
internal static ReportSource ObjectToData<T>(IEnumerable<T> data)
{
var list = new List<List<object>>();

Expand All @@ -57,8 +53,10 @@ internal static List<List<object>> ObjectToData<T>(IEnumerable<T> data)
list.Add(dataRow);
}

var source = new EnumerableReportSource();
source.Load(list);

return list;
return source;
}

internal static List<Tuple<PropertyInfo, DisplayAttribute?>> GetPropertiesAndAttributes<T>()
Expand Down
27 changes: 27 additions & 0 deletions src/Spreadsheet/TableBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.IO;
using System.Globalization;
using System.Threading.Tasks;
using System.Collections.Generic;

namespace BlackDigital.Report.Spreadsheet
{
Expand Down Expand Up @@ -73,6 +75,17 @@ public TableBuilder AddHeader(ReportSource source)
public TableBuilder AddHeader<T>(T data)
=> AddHeader(Configuration.Sources.FindSource(data));

public TableBuilder AddHeader<T>()
{
var resource = WorkbookBuilder.Resource;
CultureInfo? culture = null;

if (WorkbookBuilder.FormatProvider is CultureInfo)
culture = (CultureInfo)WorkbookBuilder.FormatProvider;

return AddHeader(ReportHelper.GetObjectHeader<T>(resource, culture));
}

public TableBuilder AddBody(ReportSource source)
{
if (HasData)
Expand All @@ -88,6 +101,20 @@ public TableBuilder AddBody(ReportSource source)
public TableBuilder AddBody<T>(T data)
=> AddBody(Configuration.Sources.FindSource(data));

public TableBuilder Fill<T>(IEnumerable<T> data)
{
var resource = WorkbookBuilder.Resource;
CultureInfo? culture = null;

if (WorkbookBuilder.FormatProvider is CultureInfo)
culture = (CultureInfo)WorkbookBuilder.FormatProvider;

AddHeader(ReportHelper.GetObjectHeader<T>(resource, culture));
AddBody(ReportHelper.ObjectToData(data));

return this;
}

#endregion "Builder"

#region "Generator"
Expand Down

0 comments on commit 61dfc9b

Please sign in to comment.