开发者

Exponential numbers to be converted to string

开发者 https://www.devze.com 2023-02-06 21:03 出处:网络
I have an issue. I\'m importing data from an excel file, data like codes and stuff. for importing I\'m using LinqToExcel

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号