Skip to content

Commit 2f70709

Browse files
authored
Merge pull request #197 from KorzhCom/dev
Version 1.5.8
2 parents 1966aca + 1a62478 commit 2f70709

File tree

9 files changed

+505
-468
lines changed

9 files changed

+505
-468
lines changed

easydata.js/packs/core/rollup.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const production = !(process.env.ROLLUP_WATCH),
1818
const banner = `
1919
/*
2020
* EasyData.JS Core v${pkg.version}
21+
* Build time: ${new Date().toLocaleString()}
2122
* Copyright 2020-${new Date().getFullYear()} Korzh.com
2223
* Licensed under MIT
2324
*/

easydata.js/packs/crud/rollup.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const production = !(process.env.ROLLUP_WATCH),
2222
const banner = `
2323
/*
2424
* EasyData.JS CRUD v${pkg.version}
25+
* Build time: ${new Date().toLocaleString()}
2526
* Copyright 2020-${new Date().getFullYear()} Korzh.com
2627
* Licensed under MIT
2728
*/

easydata.js/packs/ui/rollup.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const production = !(process.env.ROLLUP_WATCH),
2121
const banner = `
2222
/*
2323
* EasyData.JS UI v${pkg.version}
24+
* Build time: ${new Date().toLocaleString()}
2425
* Copyright 2020-${new Date().getFullYear()} Korzh.com
2526
* Licensed under MIT
2627
*/

easydata.js/version.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"version": "1.5.7",
3-
"baseVersion": "1.5.7",
4-
"assetVersion": "01_05_07",
2+
"version": "1.5.8",
3+
"baseVersion": "1.5.8",
4+
"assetVersion": "01_05_08",
55
"tag": "latest"
66
}

easydata.net/src/EasyData.Exporters.ClosedXML/Excel/ExcelDataExporter.cs

Lines changed: 57 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
using ClosedXML.Excel;
1010
using DocumentFormat.OpenXml.Spreadsheet;
11+
using DocumentFormat.OpenXml.Wordprocessing;
1112

1213
namespace EasyData.Export
1314
{
@@ -49,6 +50,12 @@ public IDataExportSettings GetDefaultSettings(CultureInfo culture = null)
4950
/// </summary>
5051
public IDataExportSettings DefaultSettings => ExcelDataExportSettings.Default;
5152

53+
/// <summary>
54+
/// Gets the current export settings passed in the ExportAsync method.
55+
/// </summary>
56+
protected ExcelDataExportSettings ExportSettings { get; private set; }
57+
58+
5259
/// <summary>
5360
/// Exports the specified data to the stream.
5461
/// </summary>
@@ -95,12 +102,12 @@ public Task ExportAsync(IEasyDataResultSet data, Stream stream, CancellationToke
95102
/// <returns>Task.</returns>
96103
public async Task ExportAsync(IEasyDataResultSet data, Stream stream, IDataExportSettings settings, CancellationToken ct = default)
97104
{
98-
var mappedSettings = MapSettings(settings);
105+
ExportSettings = MapSettings(settings);
99106

100107
// predefined formatters
101108
var predefinedFormatters = GetPredefinedFormatters(data.Cols, settings);
102109

103-
var sheetName = Utils.ToExcelSheetName(mappedSettings.Title);
110+
var sheetName = Utils.ToExcelSheetName(ExportSettings.Title);
104111

105112
var wb = new XLWorkbook();
106113
var ws = wb.Worksheets.Add(sheetName);
@@ -111,13 +118,13 @@ public async Task ExportAsync(IEasyDataResultSet data, Stream stream, IDataExpor
111118
var cellNum = startColNum;
112119

113120
var xlColID = GetExcelColumnId(startColNum);
114-
if (mappedSettings.ShowDatasetInfo) {
115-
if (!string.IsNullOrWhiteSpace(mappedSettings.Title)) {
116-
ws.Cell($"{xlColID}{cellNum}").Value = mappedSettings.Title;
121+
if (ExportSettings.ShowDatasetInfo) {
122+
if (!string.IsNullOrWhiteSpace(ExportSettings.Title)) {
123+
ws.Cell($"{xlColID}{cellNum}").Value = ExportSettings.Title;
117124
cellNum++;
118125
}
119-
if (!string.IsNullOrWhiteSpace(mappedSettings.Description)) {
120-
ws.Cell($"{xlColID}{cellNum}").Value = mappedSettings.Description;
126+
if (!string.IsNullOrWhiteSpace(ExportSettings.Description)) {
127+
ws.Cell($"{xlColID}{cellNum}").Value = ExportSettings.Description;
121128
cellNum++;
122129
}
123130
}
@@ -157,7 +164,7 @@ Task WriteRowAsync(EasyDataRow row, bool isExtraRow = false,
157164
xlColID = GetExcelColumnId(i + startColNum);
158165

159166
var cell = ws.Cell($"{xlColID}{cellNum}");
160-
167+
161168
object value;
162169
if (!string.IsNullOrEmpty(dfmt) && predefinedFormatters.TryGetValue(dfmt, out var provider)) {
163170
value = string.Format(provider, dfmt, row[i]);
@@ -182,38 +189,10 @@ Task WriteRowAsync(EasyDataRow row, bool isExtraRow = false,
182189
}
183190
}
184191

185-
if (!(value is DBNull)) {
186-
switch (excelDataType) {
187-
case XLDataType.DateTime:
188-
cell.Value = value is DateTimeOffset
189-
? ((DateTimeOffset)value).DateTime
190-
: Convert.ToDateTime(value);
191-
break;
192-
case XLDataType.Text:
193-
if (value != null) {
194-
var strValue = settings.PreserveFormatting && !column.Style.AllowAutoFormatting
195-
? "'" + value
196-
: value.ToString();
197-
cell.Value = (XLCellValue)strValue;
198-
}
199-
else {
200-
cell.Value = Blank.Value;
201-
}
202-
break;
203-
case XLDataType.Number:
204-
cell.Value = Convert.ToDouble(value);
205-
break;
206-
default:
207-
cell.Value = value.ToString();
208-
break;
209-
}
210-
}
211-
else {
212-
cell.Value = Blank.Value;
213-
}
192+
WriteCellValue(cell, value, excelDataType, column);
214193

215194
// setting the cell's format
216-
var cellFormat = GetCellFormat(excelDataType, column.DataType, mappedSettings, dfmt);
195+
var cellFormat = GetCellFormat(excelDataType, column.DataType, ExportSettings, dfmt);
217196
if (!string.IsNullOrEmpty(cellFormat)) {
218197
if (excelDataType == XLDataType.Number) {
219198
cell.Style.NumberFormat.Format = cellFormat;
@@ -245,31 +224,31 @@ Task WriteRowAsync(EasyDataRow row, bool isExtraRow = false,
245224
if (settings.RowLimit > 0 && currentRowNum >= settings.RowLimit)
246225
continue;
247226

248-
if (mappedSettings.BeforeRowInsert != null)
249-
await mappedSettings.BeforeRowInsert(row, WriteExtraRowAsync, ct).ConfigureAwait(false);
227+
if (ExportSettings.BeforeRowInsert != null)
228+
await ExportSettings.BeforeRowInsert(row, WriteExtraRowAsync, ct).ConfigureAwait(false);
250229

251230
await WriteRowAsync(row, cancellationToken: ct).ConfigureAwait(false);
252231

253232
currentRowNum++;
254233
}
255234

256-
if (mappedSettings.BeforeRowInsert != null)
257-
await mappedSettings.BeforeRowInsert(null, WriteExtraRowAsync, ct).ConfigureAwait(false);
235+
if (ExportSettings.BeforeRowInsert != null)
236+
await ExportSettings.BeforeRowInsert(null, WriteExtraRowAsync, ct).ConfigureAwait(false);
258237

259238
cellNum--;
260239

261240
// Setup styles
262241
var rngTable = ws.Range($"{startColId}{startColNum}:{endColId}{cellNum}");
263242
var rowNum = 1;
264-
if (mappedSettings.ShowDatasetInfo) {
265-
if (!string.IsNullOrWhiteSpace(mappedSettings.Title)) {
243+
if (ExportSettings.ShowDatasetInfo) {
244+
if (!string.IsNullOrWhiteSpace(ExportSettings.Title)) {
266245
rngTable.Cell(rowNum, 1).Style.Font.Bold = true;
267246
rngTable.Cell(rowNum, 1).Style.Fill.BackgroundColor = XLColor.CornflowerBlue;
268247
rngTable.Cell(rowNum, 1).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
269248
rngTable.Row(rowNum).Merge();
270249
rowNum++;
271250
}
272-
if (!string.IsNullOrWhiteSpace(mappedSettings.Description)) {
251+
if (!string.IsNullOrWhiteSpace(ExportSettings.Description)) {
273252
rngTable.Cell(rowNum, 1).Style.Font.Bold = true;
274253
rngTable.Cell(rowNum, 1).Style.Fill.BackgroundColor = XLColor.White;
275254
rngTable.Cell(rowNum, 1).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
@@ -297,6 +276,39 @@ Task WriteRowAsync(EasyDataRow row, bool isExtraRow = false,
297276
}
298277
}
299278

279+
protected virtual void WriteCellValue(IXLCell cell, object value, XLDataType xlDataType, EasyDataCol column)
280+
{
281+
if (!(value is DBNull)) {
282+
switch (xlDataType) {
283+
case XLDataType.DateTime:
284+
cell.Value = value is DateTimeOffset
285+
? ((DateTimeOffset)value).DateTime
286+
: Convert.ToDateTime(value);
287+
break;
288+
case XLDataType.Text:
289+
if (value != null) {
290+
var strValue = ExportSettings.PreserveFormatting && !column.Style.AllowAutoFormatting
291+
? "'" + value
292+
: value.ToString();
293+
cell.Value = strValue;
294+
}
295+
else {
296+
cell.Value = Blank.Value;
297+
}
298+
break;
299+
case XLDataType.Number:
300+
cell.Value = Convert.ToDouble(value);
301+
break;
302+
default:
303+
cell.Value = value.ToString();
304+
break;
305+
}
306+
}
307+
else {
308+
cell.Value = Blank.Value;
309+
}
310+
}
311+
300312
private void AdjustColumnsSize(IXLColumns columns)
301313
{
302314
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {

easydata.net/src/EasyData.Exporters.Default/Csv/CsvDataExporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public string GetFileExtension()
206206
/// <param name="displayFormat">The display format.</param>
207207
/// <returns>System.String.</returns>
208208

209-
protected string GetFormattedValue(object val, DataType dataType, CsvDataExportSettings settings, string displayFormat)
209+
protected virtual string GetFormattedValue(object val, DataType dataType, CsvDataExportSettings settings, string displayFormat)
210210
{
211211
if (val == null) {
212212
return "";

easydata.net/src/EasyData.Exporters.Default/Html/HtmlDataExporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public string GetFileExtension()
258258
/// <param name="settings">Different settings of result HTML file.</param>
259259
/// <param name="displayFormat">The display format.</param>
260260
/// <returns>System.String.</returns>
261-
protected string GetFormattedValue(object val, DataType dataType, HtmlDataExportSettings settings, string displayFormat)
261+
protected virtual string GetFormattedValue(object val, DataType dataType, HtmlDataExportSettings settings, string displayFormat)
262262
{
263263
var result = DataFormatUtils.GetFormattedValue(val, dataType, settings.Culture, displayFormat);
264264

0 commit comments

Comments
 (0)