From d6610d8428557f9528bcc767114343cd0ecd1f44 Mon Sep 17 00:00:00 2001 From: David Saavedra Date: Thu, 20 Aug 2020 17:32:58 +1000 Subject: [PATCH] Creating a flag to get the text plain of a cell ignoring its format --- ExcelMapper/ExcelMapper.cs | 4 ++++ ExcelMapper/TypeMapper.cs | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/ExcelMapper/ExcelMapper.cs b/ExcelMapper/ExcelMapper.cs index b58971b..ed589b6 100644 --- a/ExcelMapper/ExcelMapper.cs +++ b/ExcelMapper/ExcelMapper.cs @@ -847,6 +847,10 @@ Dictionary GetColumns(ISheet sheet, TypeMapper typeMapper) object GetCellValue(ICell cell, ColumnInfo targetColumn) { + if (targetColumn.TextPlain) + { + return DataFormatter.FormatCellValue(cell); + } var formulaResult = cell.CellType == CellType.Formula && (targetColumn.PropertyType != typeof(string) || targetColumn.FormulaResult); var cellType = formulaResult ? cell.CachedFormulaResultType : cell.CellType; diff --git a/ExcelMapper/TypeMapper.cs b/ExcelMapper/TypeMapper.cs index f7c449f..d0f04f2 100644 --- a/ExcelMapper/TypeMapper.cs +++ b/ExcelMapper/TypeMapper.cs @@ -103,6 +103,13 @@ public PropertyInfo Property /// true if the property will be serialized as JSON; otherwise, false. /// public bool Json { get; set; } + /// + /// Gets or sets a value indicating whether to get the value in plain text. + /// + /// + /// true if the property will be serialized as JSON; otherwise, false. + /// + public bool TextPlain { get; set; } static readonly HashSet NumericTypes = new HashSet {