Skip to content

Commit 61dfc9b

Browse files
committed
Fill object 0.5.1
1 parent 0bc9112 commit 61dfc9b

File tree

5 files changed

+51
-25
lines changed

5 files changed

+51
-25
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ dotnet add package BlackDigital.Report
8484
ReportGenerator.Spreadsheet()
8585
.AddSheet("First")
8686
.AddTable("Data")
87-
.AddHeader(new List<string>() { "Name", "Number", "ObjDate", "Time" })
88-
.AddBody(list)
87+
.Fill(list)
8988
.BuildAsync(@"test.xlsx");
9089
```
9190

@@ -188,8 +187,8 @@ The return type of BuildAsync has also changed. Instead of returning just a byte
188187
☑️ Spreadsheet cell configurations. (0.5.0)
189188
☑️ ReportFile class as build return. (0.5.0)
190189
☑️ .NET7 and .NET8 support (0.5.0)
191-
️ Header Globalization. (removed on refactory 0.5.0)
192-
️ Use DisplayAttribute to get name of columns and properties that should be generated.
190+
️ Header Globalization. (0.5.1)
191+
️ Use DisplayAttribute to get name of columns and properties that should be generated. (0.5.1)
193192
◼️ Cells with formulas.
194193
◼️ Cell value event.
195194
◼️ Tables footers.

examples/Program.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
list.Add(new("Line <1> \r\n &A", 10, DateTime.Today, TimeSpan.FromHours(3), DateOnly.FromDateTime(DateTime.Today), new(3, 0)));
2222
list.Add(new("Line <2> \r\n &B", -10, DateTime.Now, TimeSpan.FromMinutes(12), DateOnly.FromDateTime(DateTime.Today), new(5, 30)));
2323
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)));
24+
list.Add(new(null, 10.6d, DateTime.UtcNow, TimeSpan.FromMinutes(45).Add(TimeSpan.FromSeconds(31)), DateOnly.FromDateTime(DateTime.Today), new(17, 45)));
2425

2526
List<string> headers = new()
2627
{
@@ -73,7 +74,8 @@
7374
//System.Text.Json.Serialization.JsonStringEnumConverter
7475
//string a;
7576

76-
var task = ReportGenerator.Spreadsheet()
77+
/*var task = ReportGenerator.Spreadsheet()
78+
7779
.SetCompany("BlackDigital")
7880
.SetApplication("BlackDigital Report")
7981
.SetManager("TioRAC Lab")
@@ -106,24 +108,24 @@
106108
107109
task.Wait();
108110
109-
return;
111+
return;*/
110112

111-
/*task = ReportGenerator.Spreadsheet()
113+
var task = ReportGenerator.Spreadsheet()
112114
.SetCompany("BlackDigital")
113115
.SetResourceManager(Texts.ResourceManager)
114116
.SetFormatProvider(new CultureInfo("pt"))
115117
.AddSheet("First")
116118
.AddTable("Data")
117-
.FillObject(list)
118-
.Spreadsheet()
119+
.Fill(list)
120+
/*.Spreadsheet()
119121
.AddSheet("Second")
120122
.AddValue("My text header")
121123
.AddTable("Data2", "B3")
122124
.AddHeader(headers)
123125
.Fill(list2)
124126
.Sheet()
125127
.AddTable("Data3", "g4")
126-
.FillObject(list)
127-
.BuildAsync("test-pt.xlsx");*/
128+
.FillObject(list)*/
129+
.BuildAsync("D:\\Teste\\temp\\test-default.xlsx");
128130

129131
task.Wait();

src/BlackDigital.Report.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
<PropertyGroup>
44
<TargetFrameworks>net8.0;net7.0;net6.0;net5.0</TargetFrameworks>
55
<Nullable>enable</Nullable>
6-
<AssemblyVersion>0.5.0</AssemblyVersion>
7-
<FileVersion>0.5.0</FileVersion>
6+
<AssemblyVersion>0.5.1</AssemblyVersion>
7+
<FileVersion>0.5.1</FileVersion>
88
<PackageReadmeFile>README.md</PackageReadmeFile>
99
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
10-
<Version>$(VersionPrefix)0.5.0</Version>
10+
<Version>$(VersionPrefix)0.5.1</Version>
1111
<Description>Simple report generator using OpenXML. Currently it is only generating reports in spreadsheets.</Description>
1212
<PackageProjectUrl>https://github.com/blackdigital-br/BlackReport</PackageProjectUrl>
1313
<RepositoryUrl>https://github.com/blackdigital-br/BlackReport</RepositoryUrl>

src/ReportHelper.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
using System.Reflection;
55
using System.Globalization;
66
using System.Collections.Generic;
7-
using System.ComponentModel.DataAnnotations;
87
using BlackDigital.Report.Sources;
9-
8+
using System.ComponentModel.DataAnnotations;
109

1110
namespace BlackDigital.Report
1211
{
1312
internal static class ReportHelper
1413
{
15-
internal static EnumerableReportSource GetObjectHeader<T>(ResourceManager? resource, CultureInfo? culture)
14+
internal static ReportSource GetObjectHeader<T>(ResourceManager? resource, CultureInfo? culture)
1615
{
1716
var properties = GetPropertiesAndAttributes<T>();
1817
var header = properties.Select(p =>
@@ -28,18 +27,15 @@ internal static EnumerableReportSource GetObjectHeader<T>(ResourceManager? resou
2827
}
2928

3029
return columnName;
31-
}).AsEnumerable();
30+
}).ToList();
3231

33-
List<IEnumerable<string>> headerDataset = new();
34-
headerDataset.Add(header);
35-
36-
var source = new EnumerableReportSource();
37-
source.Load(headerDataset);
32+
var source = new ListReportSource();
33+
source.Load(header);
3834

3935
return source;
4036
}
4137

42-
internal static List<List<object>> ObjectToData<T>(IEnumerable<T> data)
38+
internal static ReportSource ObjectToData<T>(IEnumerable<T> data)
4339
{
4440
var list = new List<List<object>>();
4541

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

56+
var source = new EnumerableReportSource();
57+
source.Load(list);
6058

61-
return list;
59+
return source;
6260
}
6361

6462
internal static List<Tuple<PropertyInfo, DisplayAttribute?>> GetPropertiesAndAttributes<T>()

src/Spreadsheet/TableBuilder.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System.IO;
2+
using System.Globalization;
23
using System.Threading.Tasks;
4+
using System.Collections.Generic;
35

46
namespace BlackDigital.Report.Spreadsheet
57
{
@@ -73,6 +75,17 @@ public TableBuilder AddHeader(ReportSource source)
7375
public TableBuilder AddHeader<T>(T data)
7476
=> AddHeader(Configuration.Sources.FindSource(data));
7577

78+
public TableBuilder AddHeader<T>()
79+
{
80+
var resource = WorkbookBuilder.Resource;
81+
CultureInfo? culture = null;
82+
83+
if (WorkbookBuilder.FormatProvider is CultureInfo)
84+
culture = (CultureInfo)WorkbookBuilder.FormatProvider;
85+
86+
return AddHeader(ReportHelper.GetObjectHeader<T>(resource, culture));
87+
}
88+
7689
public TableBuilder AddBody(ReportSource source)
7790
{
7891
if (HasData)
@@ -88,6 +101,20 @@ public TableBuilder AddBody(ReportSource source)
88101
public TableBuilder AddBody<T>(T data)
89102
=> AddBody(Configuration.Sources.FindSource(data));
90103

104+
public TableBuilder Fill<T>(IEnumerable<T> data)
105+
{
106+
var resource = WorkbookBuilder.Resource;
107+
CultureInfo? culture = null;
108+
109+
if (WorkbookBuilder.FormatProvider is CultureInfo)
110+
culture = (CultureInfo)WorkbookBuilder.FormatProvider;
111+
112+
AddHeader(ReportHelper.GetObjectHeader<T>(resource, culture));
113+
AddBody(ReportHelper.ObjectToData(data));
114+
115+
return this;
116+
}
117+
91118
#endregion "Builder"
92119

93120
#region "Generator"

0 commit comments

Comments
 (0)