I have an issue. I'm importing data from an excel file, data like codes and stuff. for importing I'm using LinqToExcel The problem is that one of the excel's columns contains codes like "A2C235425345345" or "12441523543454454". This data of this column is not formated as string or numbers. So, when read from the excel file, instead of that value "6.57621e+009". So now i need a way to convert 开发者_C百科that value back to the initial one, using C# and .NET framework 4.0
Any ideas? Thank you!
Use an apostrophe '
before the string value and then pass it to Excel.
I am assuming you are exporting the data to Excel.
Try adding a mapping block for the convert columns.
public static List<ExcelReqests> LoadRequest( string path)
{
var excel = new ExcelQueryFactory(path);
excel.AddMapping<ExcelRequests>(x => x.COLUMNNAME, "COLUMNNAME",
s => !string.IsNullOrEmpty(s)
? decimal.TryParse(s, NumberStyles.Number | NumberStyles.AllowExponent | NumberStyles.Float, CultureInfo.InvariantCulture, out decimal dummy)
?
dummy.ToString("#0")
: s
: s);
return (from e in excel.Worksheet<ExcelRequests>(0)
select e).ToList();
}
PS: Attentention the culture dependency in the decimal convertation process.
精彩评论