Skip to content

Commit 95b4378

Browse files
authored
Merge pull request #2 from I-RzR-I/feature/TemplateGenerator
Feature/template generator
2 parents b159f66 + ea07ef1 commit 95b4378

28 files changed

+1049
-122
lines changed

docs/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## **v1.1.0.0**
2+
-> Add template generation; <br />
3+
-> Add attribute with column validation on generate template and complete it; <br />
4+
-> Small code clean and fixes; <br />
5+
-> Upgrade reference libraries.

src/DynamicExcelProvider/Abstractions/IExcelWriteFactoryProvider.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,5 +200,61 @@ Task<IResult> GenerateAsync<TDataModel>(Stream stream, IReadOnlyCollection<TData
200200
/// </returns>
201201
/// =================================================================================================
202202
Task<IResult> GenerateAsync(Stream stream, WorkbookDefinition workBook, CancellationToken cancellationToken = default);
203+
204+
/// -------------------------------------------------------------------------------------------------
205+
/// <summary>
206+
/// Generates a template.
207+
/// </summary>
208+
/// <typeparam name="T">Generic type parameter.</typeparam>
209+
/// <param name="lcid">The lcid.</param>
210+
/// <returns>
211+
/// The template.
212+
/// </returns>
213+
/// =================================================================================================
214+
IResult<byte[]> GenerateTemplate<T>(int lcid) where T : class;
215+
216+
/// -------------------------------------------------------------------------------------------------
217+
/// <summary>
218+
/// Generates a template.
219+
/// </summary>
220+
/// <typeparam name="T">Generic type parameter.</typeparam>
221+
/// <param name="stream">The stream.</param>
222+
/// <param name="lcid">The lcid.</param>
223+
/// <returns>
224+
/// The template.
225+
/// </returns>
226+
/// =================================================================================================
227+
IResult GenerateTemplate<T>(MemoryStream stream, int lcid) where T : class;
228+
229+
/// -------------------------------------------------------------------------------------------------
230+
/// <summary>
231+
/// Generates a template asynchronous.
232+
/// </summary>
233+
/// <typeparam name="T">Generic type parameter.</typeparam>
234+
/// <param name="lcid">The lcid.</param>
235+
/// <param name="cancellationToken">
236+
/// (Optional) A token that allows processing to be cancelled.
237+
/// </param>
238+
/// <returns>
239+
/// The template asynchronous.
240+
/// </returns>
241+
/// =================================================================================================
242+
Task<IResult<byte[]>> GenerateTemplateAsync<T>(int lcid, CancellationToken cancellationToken = default) where T : class;
243+
244+
/// -------------------------------------------------------------------------------------------------
245+
/// <summary>
246+
/// Generates a template asynchronous.
247+
/// </summary>
248+
/// <typeparam name="T">Generic type parameter.</typeparam>
249+
/// <param name="stream">The stream.</param>
250+
/// <param name="lcid">The lcid.</param>
251+
/// <param name="cancellationToken">
252+
/// (Optional) A token that allows processing to be cancelled.
253+
/// </param>
254+
/// <returns>
255+
/// The template asynchronous.
256+
/// </returns>
257+
/// =================================================================================================
258+
Task<IResult> GenerateTemplateAsync<T>(MemoryStream stream, int lcid, CancellationToken cancellationToken = default) where T : class;
203259
}
204260
}

src/DynamicExcelProvider/Attributes/ExcelPropNameAttribute.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ public ExcelPropNameAttribute(string propertyName, int cultureInfoId, bool wrapT
9191
IsItalic = isItalic;
9292
}
9393

94+
/// -------------------------------------------------------------------------------------------------
95+
/// <summary>
96+
/// Initializes a new instance of the <see cref="ExcelPropNameAttribute"/> class.
97+
/// </summary>
98+
/// =================================================================================================
99+
public ExcelPropNameAttribute()
100+
{
101+
}
102+
94103
/// -------------------------------------------------------------------------------------------------
95104
/// <summary>
96105
/// Gets or sets the localized property name.
@@ -109,7 +118,7 @@ public ExcelPropNameAttribute(string propertyName, int cultureInfoId, bool wrapT
109118
/// Information describing the culture.
110119
/// </value>
111120
/// =================================================================================================
112-
public CultureInfo CultureInfo { get; }
121+
public CultureInfo CultureInfo { get; set; }
113122

114123
/// -------------------------------------------------------------------------------------------------
115124
/// <summary>
@@ -129,7 +138,7 @@ public ExcelPropNameAttribute(string propertyName, int cultureInfoId, bool wrapT
129138
/// <see langword="true" /> if include it; otherwise, <see langword="false" />.
130139
/// </value>
131140
/// =================================================================================================
132-
public bool InResult { get; set; }
141+
public bool InResult { get; set; } = false;
133142

134143
/// -------------------------------------------------------------------------------------------------
135144
/// <summary>
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
// ***********************************************************************
2+
// Assembly : RzR.Shared.Export.DynamicExcelProvider
3+
// Author : RzR
4+
// Created On : 2024-10-03 19:03
5+
//
6+
// Last Modified By : RzR
7+
// Last Modified On : 2024-10-04 19:02
8+
// ***********************************************************************
9+
// <copyright file="ExcelPropValidationAttribute.cs" company="">
10+
// Copyright (c) RzR. All rights reserved.
11+
// </copyright>
12+
//
13+
// <summary>
14+
// </summary>
15+
// ***********************************************************************
16+
17+
#region U S A G E S
18+
19+
using DynamicExcelProvider.Enums;
20+
using System;
21+
using System.Collections.Generic;
22+
23+
#endregion
24+
25+
namespace DynamicExcelProvider.Attributes
26+
{
27+
/// -------------------------------------------------------------------------------------------------
28+
/// <summary>
29+
/// Attribute for excel property validation.
30+
/// </summary>
31+
/// <seealso cref="T:Attribute"/>
32+
/// =================================================================================================
33+
[AttributeUsage(AttributeTargets.Property)]
34+
public class ExcelPropValidationAttribute : Attribute
35+
{
36+
/// <inheritdoc/>
37+
public ExcelPropValidationAttribute(
38+
ValidationType validationType,
39+
ValidationOperatorType operatorType,
40+
string[] allowedValues,
41+
object minValue,
42+
object maxValue,
43+
string errorMessage = null,
44+
string promptMessage = null,
45+
bool allowEmpty = true
46+
/*bool showListInDropDown = true*/)
47+
{
48+
ValidationType = validationType;
49+
OperatorType = operatorType;
50+
AllowedValues = allowedValues;
51+
MinValue = (int?)minValue;
52+
MaxValue = (int?)maxValue;
53+
ErrorMessage = errorMessage;
54+
PromptMessage = promptMessage;
55+
AllowEmpty = allowEmpty;
56+
//ShowListInDropDown = showListInDropDown;
57+
ShowListInDropDown = false;
58+
}
59+
60+
/// <inheritdoc/>
61+
public ExcelPropValidationAttribute(
62+
ValidationType validationType,
63+
ValidationOperatorType operatorType,
64+
string[] allowedValues,
65+
string errorMessage = null,
66+
string promptMessage = null,
67+
bool allowEmpty = true
68+
/*bool showListInDropDown = true*/)
69+
{
70+
ValidationType = validationType;
71+
OperatorType = operatorType;
72+
AllowedValues = allowedValues;
73+
ErrorMessage = errorMessage;
74+
PromptMessage = promptMessage;
75+
AllowEmpty = allowEmpty;
76+
//ShowListInDropDown = showListInDropDown;
77+
ShowListInDropDown = false;
78+
}
79+
80+
/// <inheritdoc/>
81+
public ExcelPropValidationAttribute(
82+
ValidationType validationType,
83+
ValidationOperatorType operatorType,
84+
object minValue,
85+
object maxValue,
86+
string errorMessage = null,
87+
string promptMessage = null,
88+
bool allowEmpty = true)
89+
{
90+
ValidationType = validationType;
91+
OperatorType = operatorType;
92+
MinValue = (int?)minValue;
93+
MaxValue = (int?)maxValue;
94+
ErrorMessage = errorMessage;
95+
PromptMessage = promptMessage;
96+
AllowEmpty = allowEmpty;
97+
}
98+
99+
/// <inheritdoc/>
100+
public ExcelPropValidationAttribute(
101+
ValidationType validationType,
102+
ValidationOperatorType operatorType,
103+
object minValue,
104+
string errorMessage = null,
105+
string promptMessage = null,
106+
bool allowEmpty = true)
107+
{
108+
ValidationType = validationType;
109+
OperatorType = operatorType;
110+
MinValue = (int?)minValue;
111+
ErrorMessage = errorMessage;
112+
PromptMessage = promptMessage;
113+
AllowEmpty = allowEmpty;
114+
}
115+
116+
/// -------------------------------------------------------------------------------------------------
117+
/// <summary>
118+
/// Initializes a new instance of the <see cref="ExcelPropValidationAttribute"/> class.
119+
/// </summary>
120+
/// =================================================================================================
121+
public ExcelPropValidationAttribute()
122+
{
123+
}
124+
125+
/// -------------------------------------------------------------------------------------------------
126+
/// <summary>
127+
/// Gets or sets the type of the validation.
128+
/// </summary>
129+
/// <value>
130+
/// The type of the validation.
131+
/// </value>
132+
/// =================================================================================================
133+
public ValidationType ValidationType { get; set; }
134+
135+
/// -------------------------------------------------------------------------------------------------
136+
/// <summary>
137+
/// Gets or sets the type of the operator.
138+
/// </summary>
139+
/// <value>
140+
/// The type of the operator.
141+
/// </value>
142+
/// =================================================================================================
143+
public ValidationOperatorType OperatorType { get; set; }
144+
145+
/// -------------------------------------------------------------------------------------------------
146+
/// <summary>
147+
/// Gets or sets the allowed values.
148+
/// </summary>
149+
/// <value>
150+
/// The allowed values.
151+
/// </value>
152+
/// =================================================================================================
153+
public IEnumerable<string> AllowedValues { get; set; }
154+
155+
/// -------------------------------------------------------------------------------------------------
156+
/// <summary>
157+
/// Gets or sets the minimum value (INT_32).
158+
/// </summary>
159+
/// <value>
160+
/// The minimum value.
161+
/// </value>
162+
/// =================================================================================================
163+
public object MinValue { get; set; }
164+
165+
/// -------------------------------------------------------------------------------------------------
166+
/// <summary>
167+
/// Gets or sets the maximum value (INT_32).
168+
/// </summary>
169+
/// <value>
170+
/// The maximum value.
171+
/// </value>
172+
/// =================================================================================================
173+
public object MaxValue { get; set; }
174+
175+
/// -------------------------------------------------------------------------------------------------
176+
/// <summary>
177+
/// Gets or sets a message describing the error.
178+
/// </summary>
179+
/// <value>
180+
/// A message describing the error.
181+
/// </value>
182+
/// =================================================================================================
183+
public string ErrorMessage { get; set; }
184+
185+
/// -------------------------------------------------------------------------------------------------
186+
/// <summary>
187+
/// Gets or sets a message describing the prompt.
188+
/// </summary>
189+
/// <value>
190+
/// A message describing the prompt.
191+
/// </value>
192+
/// =================================================================================================
193+
public string PromptMessage { get; set; }
194+
195+
/// -------------------------------------------------------------------------------------------------
196+
/// <summary>
197+
/// Gets or sets a value indicating whether we allow empty.
198+
/// </summary>
199+
/// <value>
200+
/// True if allow empty, false if not.
201+
/// </value>
202+
/// =================================================================================================
203+
public bool AllowEmpty { get; set; }
204+
205+
/// -------------------------------------------------------------------------------------------------
206+
/// <summary>
207+
/// Gets or sets a value indicating whether the list in drop down is shown.
208+
/// </summary>
209+
/// <value>
210+
/// True if show list in drop down, false if not.
211+
/// </value>
212+
/// =================================================================================================
213+
internal bool ShowListInDropDown { get; set; }
214+
}
215+
}

src/DynamicExcelProvider/DynamicExcelProvider.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252

5353
<ItemGroup>
5454
<PackageReference Include="AggregatedGenericResultMessage" Version="1.3.3.6068" />
55-
<PackageReference Include="DocumentFormat.OpenXml" Version="3.0.1" />
56-
<PackageReference Include="DomainCommonExtensions" Version="1.1.0.0" />
55+
<PackageReference Include="DocumentFormat.OpenXml" Version="3.1.0" />
56+
<PackageReference Include="DomainCommonExtensions" Version="1.3.0" />
5757
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
5858
</ItemGroup>
5959

0 commit comments

Comments
 (0)