public static bool IsNumeric(Type typeUnderTest) { NumericTypes test = new NumericTypes { typeof(decimal), typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(float), typeof(double) }; return(test.Contains(typeUnderTest)); }
private static void SetCellValue(string cellValue, Type cellType, Cell newCell, XlSharedStringsTable stringsTable) { if (NumericTypes.IsNumeric(cellType)) { newCell.CellValue = new CellValue(cellValue.ToString()); newCell.DataType = new EnumValue <CellValues>(CellValues.Number); } else if ((cellType.Name == "String") || (cellType.Name == "DateTime")) { // You can only mark a DateTime as a CellValues.Date if // It conforms to a specific ISO 8601 format. // It then is displayed as a number. So for the best presentation, // we treat them as strings. int stringIndex = stringsTable.LookupStringIndex(cellValue); newCell.CellValue = new CellValue(stringIndex.ToString()); newCell.DataType = new EnumValue <CellValues>(CellValues.SharedString); } }