From d26e0caffa81c9606a62e6306d6327543dc3f656 Mon Sep 17 00:00:00 2001 From: chei Date: Wed, 16 Feb 2022 19:17:28 +0800 Subject: [PATCH] =?UTF-8?q?ExcelColumnName=E7=94=B1Property.Name=E5=8F=98?= =?UTF-8?q?=E6=9B=B4=E4=B8=BACustomAttribute.DisplayName=20.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MiniExcel/Utils/CustomPropertyHelper.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/MiniExcel/Utils/CustomPropertyHelper.cs b/src/MiniExcel/Utils/CustomPropertyHelper.cs index e6a0f60..7e8d24f 100644 --- a/src/MiniExcel/Utils/CustomPropertyHelper.cs +++ b/src/MiniExcel/Utils/CustomPropertyHelper.cs @@ -160,6 +160,8 @@ private static IEnumerable GetExcelPropertyInfo(Type ty { formatToStringMethod = excludeNullableType.GetMethod("ToString", new[] { typeof(string) }); } + //https://gitee.com/dotnetchina/MiniExcel/issues/I4TXGT + string dispName = p.GetCustomAttribute()?.DisplayName ?? ""; MethodInfo cultureToStringMethod = excludeNullableType.GetMethod("ToString", new[] { typeof(CultureInfo) }); return new ExcelCustomPropertyInfo { @@ -168,7 +170,7 @@ private static IEnumerable GetExcelPropertyInfo(Type ty ExcludeNullableType = excludeNullableType, Nullable = gt != null, ExcelColumnAliases = excelColumnName?.Aliases, - ExcelColumnName = excelColumnName?.ExcelColumnName ?? p.Name, + ExcelColumnName = excelColumnName?.ExcelColumnName ?? (dispName == "" ? p.Name : dispName), ExcelColumnIndex = p.GetAttribute()?.ExcelColumnIndex, ExcelColumnWidth = p.GetAttribute()?.ExcelColumnWidth, ExcelFormat = excelFormat, -- Gitee