Commit 9093a810 by lcx

读取Excel时兼容读取科学计数法的字符值

parent 08cbd670
...@@ -5,11 +5,10 @@ ...@@ -5,11 +5,10 @@
namespace Performance.Infrastructure namespace Performance.Infrastructure
{ {
/// <summary> /// <summary>
/// 类型转换 /// 类型转换
/// </summary> /// </summary>
public static class ConvertHelper public static class ConvertHelper
{ {
public static int TryInt(string inValue, int defaultValue = default(int)) public static int TryInt(string inValue, int defaultValue = default(int))
{ {
int ret = defaultValue; int ret = defaultValue;
...@@ -27,7 +26,7 @@ public static long TryLong(string inValue, long defaultValue = default(int)) ...@@ -27,7 +26,7 @@ public static long TryLong(string inValue, long defaultValue = default(int))
public static decimal TryDecimal(string inValue, decimal defaultValue = default(decimal)) public static decimal TryDecimal(string inValue, decimal defaultValue = default(decimal))
{ {
decimal ret = defaultValue; decimal ret = defaultValue;
decimal.TryParse(inValue, out ret); decimal.TryParse(inValue, System.Globalization.NumberStyles.Float, default, out ret);
return ret; return ret;
} }
...@@ -38,7 +37,6 @@ public static DateTime TryDateTime(string inValue, DateTime defaultValue = defau ...@@ -38,7 +37,6 @@ public static DateTime TryDateTime(string inValue, DateTime defaultValue = defau
return ret; return ret;
} }
/// <summary> /// <summary>
/// 返回默认值 /// 返回默认值
/// </summary> /// </summary>
...@@ -70,10 +68,8 @@ public static T To<T>(object value, T defaultValue = default(T)) ...@@ -70,10 +68,8 @@ public static T To<T>(object value, T defaultValue = default(T))
} }
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <typeparam name = "T"></typeparam> /// <typeparam name = "T"></typeparam>
/// <param name = "value">The value.</param> /// <param name = "value">The value.</param>
...@@ -95,7 +91,5 @@ public static T To<T>(object value, T defaultValue, bool ignoreException) ...@@ -95,7 +91,5 @@ public static T To<T>(object value, T defaultValue, bool ignoreException)
} }
return To<T>(value); return To<T>(value);
} }
} }
} }
\ No newline at end of file
...@@ -41,7 +41,7 @@ public List<IPerData> ReadData(ISheet sheet, List<PerHeader> perHeader) ...@@ -41,7 +41,7 @@ public List<IPerData> ReadData(ISheet sheet, List<PerHeader> perHeader)
{ {
object @object = row.GetCell(point).GetValue(); object @object = row.GetCell(point).GetValue();
if (item.IsNumber) if (item.IsNumber)
@object = ConvertHelper.To<decimal?>(@object); @object = ConvertHelper.TryDecimal(@object?.ToString());
if (dic.Keys.Contains(item.Field)) if (dic.Keys.Contains(item.Field))
dic[item.Field] = @object; dic[item.Field] = @object;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment