Example #1
0
 /// <summary>
 /// 给指定Cell设置值
 /// </summary>
 /// <param name="cell">Excel单元格</param>
 /// <param name="value">值对象</param>
 /// <returns></returns>
 public static bool SetCellValue(ICell cell, Object value)
 {
     if (cell != null && value != null)
     {
         if (value.GetType() == typeof(DateTime) || value.GetType() == typeof(DateTime?))
         {
             cell.SetCellValue((DateTime)value);
         }
         else if (value.GetType() == typeof(Boolean) || value.GetType() == typeof(Boolean?))
         {
             cell.SetCellValue((Boolean)value);
         }
         else if (value.GetType() == typeof(IRichTextString))
         {
             cell.SetCellValue((Boolean)value);
         }
         else if (NPOIUtil.NumberType(value.GetType()))
         {
             cell.SetCellValue(Double.Parse(value.ToString()));
         }
         else
         {
             cell.SetCellValue(value.ToString());
         }
         return(true);
     }
     return(false);
 }
Example #2
0
            /// <summary>
            /// 初始化参数
            /// </summary>
            private void init()
            {
                //FieldName convert to lower case
                DateTimeFields.ForEach(p => p = p.ToLower());
                DoubleFields.ForEach(p => p   = p.ToLower());
                AllFields.ForEach(p => p      = p.ToLower());


                if (AllFields.Count == 0)
                {
                    AllFields = this.GetDefaultFields();
                }

                //自动识别
                if (TypeDetectable)
                {
                    foreach (String field in AllFields)
                    {
                        Type type = dt.Columns[field].DataType;
                        if (typeof(DateTime) == type)
                        {
                            DateTimeFields.Add(field);
                        }
                        else if (NPOIUtil.NumberType(type))
                        {
                            DoubleFields.Add(field);
                        }
                    }
                }
            }
Example #3
0
 private void init()
 {
     if (AllFields.Count == 0)
     {
         AllFields = GetDefaultFields();
     }
     //自动识别
     if (TypeDetectable)
     {
         foreach (String field in AllFields)
         {
             Type type = typeof(T).GetProperty(field).PropertyType;
             if (typeof(DateTime) == type || typeof(DateTime?) == type)
             {
                 DateTimeFields.Add(field);
             }
             else if (NPOIUtil.NumberType(type))
             {
                 DoubleFields.Add(field);
             }
         }
     }
 }