Skip to content

Commit 7ff53af

Browse files
committed
优化导出excel时数字类型的转换
1 parent 54d0189 commit 7ff53af

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -396,29 +396,29 @@ IEnumerable<string> GetListValues(string cellValues, string propertyName)
396396
{
397397
for (int j = 0; j < propertyInfo.Count; j++)
398398
{
399-
string cellValue = null;
399+
object cellValue = null;
400400
if (dateArr != null && dateArr.Contains(propertyInfo[j].Name))
401401
{
402402
object value = propertyInfo[j].GetValue(list[i]);
403403
cellValue = value == null ? "" : ((DateTime)value).ToString("yyyy-MM-dd HH:mm:sss").Replace(" 00:00:00", "");
404404
}
405405
else
406406
{
407-
cellValue = (propertyInfo[j].GetValue(list[i]) ?? "").ToString();
407+
cellValue = propertyInfo[j].GetValue(list[i]);
408408
}
409-
if (dicNoKeys.Exists(x => x.ColumnName == propertyInfo[j].Name))
409+
if (cellValue!=null&&dicNoKeys.Exists(x => x.ColumnName == propertyInfo[j].Name))
410410
{
411411
//2021.01.24修复多选类型,导出excel文件没有转换数据源的问题
412412
if (selectList.Contains(propertyInfo[j].Name))
413413
{
414-
cellValue = string.Join(",", GetListValues(cellValue, propertyInfo[j].Name));
414+
cellValue = string.Join(",", GetListValues(cellValue.ToString(), propertyInfo[j].Name));
415415
}
416416
else
417417
{
418418
cellOptions.Where(x => x.ColumnName == propertyInfo[j].Name)
419419
.Select(s => s.KeyValues)
420420
.FirstOrDefault()
421-
.TryGetValue(cellValue, out string result);
421+
.TryGetValue(cellValue.ToString(), out string result);
422422
cellValue = result ?? cellValue;
423423
}
424424

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -396,29 +396,29 @@ IEnumerable<string> GetListValues(string cellValues, string propertyName)
396396
{
397397
for (int j = 0; j < propertyInfo.Count; j++)
398398
{
399-
string cellValue = null;
399+
object cellValue = null;
400400
if (dateArr != null && dateArr.Contains(propertyInfo[j].Name))
401401
{
402402
object value = propertyInfo[j].GetValue(list[i]);
403403
cellValue = value == null ? "" : ((DateTime)value).ToString("yyyy-MM-dd HH:mm:sss").Replace(" 00:00:00", "");
404404
}
405405
else
406406
{
407-
cellValue = (propertyInfo[j].GetValue(list[i]) ?? "").ToString();
407+
cellValue = propertyInfo[j].GetValue(list[i]);
408408
}
409-
if (dicNoKeys.Exists(x => x.ColumnName == propertyInfo[j].Name))
409+
if (cellValue!=null&&dicNoKeys.Exists(x => x.ColumnName == propertyInfo[j].Name))
410410
{
411411
//2021.01.24修复多选类型,导出excel文件没有转换数据源的问题
412412
if (selectList.Contains(propertyInfo[j].Name))
413413
{
414-
cellValue = string.Join(",", GetListValues(cellValue, propertyInfo[j].Name));
414+
cellValue = string.Join(",", GetListValues(cellValue.ToString(), propertyInfo[j].Name));
415415
}
416416
else
417417
{
418418
cellOptions.Where(x => x.ColumnName == propertyInfo[j].Name)
419419
.Select(s => s.KeyValues)
420420
.FirstOrDefault()
421-
.TryGetValue(cellValue, out string result);
421+
.TryGetValue(cellValue.ToString(), out string result);
422422
cellValue = result ?? cellValue;
423423
}
424424

0 commit comments

Comments
 (0)