/// <summary> /// 给单元格赋值,并设置数据类型 /// </summary> /// <param name="cell"></param> /// <param name="type"></param> /// <param name="cellStyle"></param> /// <param name="value"></param> public static void SetCellValueT(this ICell cell, ExcelColumType type, ICellStyle cellStyle, object value) { if (value == null) { return; } if (type == ExcelColumType.Bool) { cell.SetCellValue((bool)value); } else if (type == ExcelColumType.DateTime) { cell.SetCellValue((DateTime)value); } else if (type == ExcelColumType.Double) { if (double.TryParse(value.ToString(), out double number)) { cell.SetCellValue(number); } else { cell.SetCellValue(value.ToString()); } } else { cell.SetCellValue(value.ToString()); } cell.CellStyle = cellStyle; }
public ExcelField(string name, ExcelColumType type) { Name = name; Type = type; }