Skip to content

Commit c33d9f0

Browse files
committed
修复多选类型,导出excel文件没有转换数据源的问题
1 parent d4c8b36 commit c33d9f0

File tree

2 files changed

+82
-18
lines changed

2 files changed

+82
-18
lines changed

Vue.Net/VOL.Core/Utilities/EPPlusHelper.cs

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public static WebResponseContent ReadToDataTable<T>(string path, Expression<Func
104104
//2020.09.20增加判断数据源是否有值
105105
if (!string.IsNullOrEmpty(options.DropNo) && !string.IsNullOrEmpty(value))
106106
{
107-
if (options.KeyValues==null)
107+
if (options.KeyValues == null)
108108
{
109109
return responseContent.Error($"[{options.ColumnCNName}]字段数字典编号[{options.DropNo}]缺失,请检查字典配置");
110110
}
@@ -284,7 +284,10 @@ public static string Export<T>(List<T> list, IEnumerable<string> exportColumns,
284284
//获取所有有值的数据源
285285
var dicNoKeys = cellOptions
286286
.Where(x => !string.IsNullOrEmpty(x.DropNo) && x.KeyValues != null && x.KeyValues.Keys.Count > 0)
287-
.Select(x => new { x.DropNo, x.ColumnName }).Distinct().ToList();
287+
.Select(x => new { x.DropNo, x.ColumnName, x.SearchType, x.EditType }).Distinct().ToList();
288+
//2021.01.24修复多选类型,导出excel文件没有转换数据源的问题
289+
var selectList = dicNoKeys.Where(x => x.SearchType == "checkbox" || x.SearchType == "selectList" || x.EditType == "checkbox" || x.EditType == "selectList")
290+
.Select(s => s.ColumnName).ToArray();
288291

289292
List<PropertyInfo> propertyInfo = null;
290293

@@ -375,6 +378,20 @@ public static string Export<T>(List<T> list, IEnumerable<string> exportColumns,
375378
package.SaveAs(new FileInfo(fullPath));
376379
return fullPath;
377380
}
381+
//2021.01.24修复多选类型,导出excel文件没有转换数据源的问题
382+
IEnumerable<string> GetListValues(string cellValues, string propertyName)
383+
{
384+
var values = cellValues.Split(",");
385+
for (int i = 0; i < values.Length; i++)
386+
{
387+
cellOptions.Where(x => x.ColumnName == propertyName)
388+
.Select(s => s.KeyValues)
389+
.FirstOrDefault()
390+
.TryGetValue(values[i], out string result);
391+
yield return result ?? values[i];
392+
}
393+
394+
}
378395
for (int i = 0; i < list.Count; i++)
379396
{
380397
for (int j = 0; j < propertyInfo.Count; j++)
@@ -391,11 +408,20 @@ public static string Export<T>(List<T> list, IEnumerable<string> exportColumns,
391408
}
392409
if (dicNoKeys.Exists(x => x.ColumnName == propertyInfo[j].Name))
393410
{
394-
cellOptions.Where(x => x.ColumnName == propertyInfo[j].Name)
395-
.Select(s => s.KeyValues)
396-
.FirstOrDefault()
397-
.TryGetValue(cellValue, out string result);
398-
cellValue = result ?? cellValue;
411+
//2021.01.24修复多选类型,导出excel文件没有转换数据源的问题
412+
if (selectList.Contains(propertyInfo[j].Name))
413+
{
414+
cellValue = string.Join(",", GetListValues(cellValue, propertyInfo[j].Name));
415+
}
416+
else
417+
{
418+
cellOptions.Where(x => x.ColumnName == propertyInfo[j].Name)
419+
.Select(s => s.KeyValues)
420+
.FirstOrDefault()
421+
.TryGetValue(cellValue, out string result);
422+
cellValue = result ?? cellValue;
423+
}
424+
399425
}
400426
worksheet.Cells[i + 2, j + 1].Value = cellValue;
401427
}
@@ -435,7 +461,10 @@ private static List<CellOptions> GetExportColumnInfo(string tableName, bool teml
435461
ColumnCNName = c.ColumnCnName,
436462
DropNo = c.DropNo,
437463
Requierd = c.IsNull > 0 ? false : true,
438-
ColumnWidth = c.ColumnWidth ?? 90
464+
ColumnWidth = c.ColumnWidth ?? 90,
465+
EditType = c.EditType,
466+
SearchType = c.SearchType
467+
439468
}).ToList();
440469

441470

@@ -479,7 +508,10 @@ public class CellOptions
479508
public int ColumnWidth { get; set; }//导出列的宽度,代码生成维护的宽度
480509
public bool Requierd { get; set; } //是否必填
481510
public int Index { get; set; }//列所在模板的序号(导入用)
482-
//对应字典项维护的Key,Value
511+
//2021.01.24修复多选类型,导出excel文件没有转换数据源的问题
512+
public string EditType { get; set; }
513+
public string SearchType { get; set; }
514+
//对应字典项维护的Key,Value
483515
public Dictionary<string, string> KeyValues { get; set; }
484516
//public string Value { get; set; } //对应字典项维护的Value
485517
//public string Name { get; set; } //对应字典项显示的名称

开发版dev/Vue.NetCore/Vue.Net/VOL.Core/Utilities/EPPlusHelper.cs

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public static WebResponseContent ReadToDataTable<T>(string path, Expression<Func
104104
//2020.09.20增加判断数据源是否有值
105105
if (!string.IsNullOrEmpty(options.DropNo) && !string.IsNullOrEmpty(value))
106106
{
107-
if (options.KeyValues==null)
107+
if (options.KeyValues == null)
108108
{
109109
return responseContent.Error($"[{options.ColumnCNName}]字段数字典编号[{options.DropNo}]缺失,请检查字典配置");
110110
}
@@ -284,7 +284,10 @@ public static string Export<T>(List<T> list, IEnumerable<string> exportColumns,
284284
//获取所有有值的数据源
285285
var dicNoKeys = cellOptions
286286
.Where(x => !string.IsNullOrEmpty(x.DropNo) && x.KeyValues != null && x.KeyValues.Keys.Count > 0)
287-
.Select(x => new { x.DropNo, x.ColumnName }).Distinct().ToList();
287+
.Select(x => new { x.DropNo, x.ColumnName, x.SearchType, x.EditType }).Distinct().ToList();
288+
//2021.01.24修复多选类型,导出excel文件没有转换数据源的问题
289+
var selectList = dicNoKeys.Where(x => x.SearchType == "checkbox" || x.SearchType == "selectList" || x.EditType == "checkbox" || x.EditType == "selectList")
290+
.Select(s => s.ColumnName).ToArray();
288291

289292
List<PropertyInfo> propertyInfo = null;
290293

@@ -375,6 +378,20 @@ public static string Export<T>(List<T> list, IEnumerable<string> exportColumns,
375378
package.SaveAs(new FileInfo(fullPath));
376379
return fullPath;
377380
}
381+
//2021.01.24修复多选类型,导出excel文件没有转换数据源的问题
382+
IEnumerable<string> GetListValues(string cellValues, string propertyName)
383+
{
384+
var values = cellValues.Split(",");
385+
for (int i = 0; i < values.Length; i++)
386+
{
387+
cellOptions.Where(x => x.ColumnName == propertyName)
388+
.Select(s => s.KeyValues)
389+
.FirstOrDefault()
390+
.TryGetValue(values[i], out string result);
391+
yield return result ?? values[i];
392+
}
393+
394+
}
378395
for (int i = 0; i < list.Count; i++)
379396
{
380397
for (int j = 0; j < propertyInfo.Count; j++)
@@ -391,11 +408,20 @@ public static string Export<T>(List<T> list, IEnumerable<string> exportColumns,
391408
}
392409
if (dicNoKeys.Exists(x => x.ColumnName == propertyInfo[j].Name))
393410
{
394-
cellOptions.Where(x => x.ColumnName == propertyInfo[j].Name)
395-
.Select(s => s.KeyValues)
396-
.FirstOrDefault()
397-
.TryGetValue(cellValue, out string result);
398-
cellValue = result ?? cellValue;
411+
//2021.01.24修复多选类型,导出excel文件没有转换数据源的问题
412+
if (selectList.Contains(propertyInfo[j].Name))
413+
{
414+
cellValue = string.Join(",", GetListValues(cellValue, propertyInfo[j].Name));
415+
}
416+
else
417+
{
418+
cellOptions.Where(x => x.ColumnName == propertyInfo[j].Name)
419+
.Select(s => s.KeyValues)
420+
.FirstOrDefault()
421+
.TryGetValue(cellValue, out string result);
422+
cellValue = result ?? cellValue;
423+
}
424+
399425
}
400426
worksheet.Cells[i + 2, j + 1].Value = cellValue;
401427
}
@@ -435,7 +461,10 @@ private static List<CellOptions> GetExportColumnInfo(string tableName, bool teml
435461
ColumnCNName = c.ColumnCnName,
436462
DropNo = c.DropNo,
437463
Requierd = c.IsNull > 0 ? false : true,
438-
ColumnWidth = c.ColumnWidth ?? 90
464+
ColumnWidth = c.ColumnWidth ?? 90,
465+
EditType = c.EditType,
466+
SearchType = c.SearchType
467+
439468
}).ToList();
440469

441470

@@ -479,7 +508,10 @@ public class CellOptions
479508
public int ColumnWidth { get; set; }//导出列的宽度,代码生成维护的宽度
480509
public bool Requierd { get; set; } //是否必填
481510
public int Index { get; set; }//列所在模板的序号(导入用)
482-
//对应字典项维护的Key,Value
511+
//2021.01.24修复多选类型,导出excel文件没有转换数据源的问题
512+
public string EditType { get; set; }
513+
public string SearchType { get; set; }
514+
//对应字典项维护的Key,Value
483515
public Dictionary<string, string> KeyValues { get; set; }
484516
//public string Value { get; set; } //对应字典项维护的Value
485517
//public string Name { get; set; } //对应字典项显示的名称

0 commit comments

Comments
 (0)