public static void SetCellValue(this Cell cell, object value, Type type) { if (type == typeof(string)) { cell.RemoveAllChildren(); cell.Append(new InlineString(new Text((string)value))); cell.DataType = CellValues.InlineString; } else { string excelValue = value == null ? "" : type.UnNullify() == typeof(DateTime) ? ExcelExtensions.ToExcelDate(((DateTime)value)) : type.UnNullify() == typeof(bool) ? (((bool)value) ? "TRUE": "FALSE") : IsNumber(type.UnNullify()) ? ExcelExtensions.ToExcelNumber(Convert.ToDecimal(value)) : value.ToString(); cell.CellValue = new CellValue(excelValue); } }
public Cell Cell(object value, TemplateCells template, UInt32Value styleIndex) { string excelValue = value == null ? "" : (template == TemplateCells.Date || template == TemplateCells.DateTime) ? ExcelExtensions.ToExcelDate(((DateTime)value)) : (template.ToString().StartsWith("Decimal")) ? ExcelExtensions.ToExcelNumber(Convert.ToDecimal(value)) : (template == TemplateCells.Boolean) ? ToYesNo((bool)value) : (template == TemplateCells.Enum) ? ((Enum)value)?.NiceToString() : value.ToString(); Cell cell = IsInlineString(template)? new Cell(new InlineString(new Text { Text = excelValue })) { DataType = CellValues.InlineString } : new Cell { CellValue = new CellValue(excelValue), DataType = null }; cell.StyleIndex = styleIndex; return(cell); }
#pragma warning disable CA1822 // Mark members as static public Cell Cell(object?value, DefaultStyle template, UInt32Value styleIndex) #pragma warning restore CA1822 // Mark members as static { string excelValue = value == null ? "" : (template == DefaultStyle.Date || template == DefaultStyle.DateTime) ? ExcelExtensions.ToExcelDate(((DateTime)value)) : (template.ToString().StartsWith("Decimal")) ? ExcelExtensions.ToExcelNumber(Convert.ToDecimal(value)) : (template == DefaultStyle.Boolean) ? ToYesNo((bool)value) : (template == DefaultStyle.Enum) ? ((Enum)value).NiceToString() : value.ToString() !; Cell cell = IsInlineString(template)? new Cell(new InlineString(new Text { Text = excelValue })) { DataType = CellValues.InlineString } : new Cell { CellValue = new CellValue(excelValue), DataType = null }; cell.StyleIndex = styleIndex; return(cell); }