Excel18位数字类型转换C#类型
1.问题描述
在读取Excel的时候数字如 身份证 手机号 或其他数字类型 会被Excel常规模式转换成1.000E+17 或其他类似的数字
当C#读取转换时 可根据情况 如 手机号11位 可直接读取或用int型转换 但当是身份证 18位 超过int型最大值 用double类型转换还是上面的 必须用long类型转换
2.解决思路
如果身份证在Excel中为文本模式 如:1111111111111111111
可以直接用:
[csharp]
string s=long.Parse("11111111111111111").ToString();
如果在Excel中为常规模式 如:1.1111E+17
用上面的方法会报错 因为Parse方法默认解析格式为Integer类型,可以指定参数格式解决
[csharp]
string s=long.Parse("11111111111111111", System.Globalization.NumberStyles.Float).ToString();
http://www.xici.net/d201420213.htm
http://www.xici.net/d201420206.htm
http://www.xici.net/d201420200.htm
http://www.xici.net/d201420198.htm
http://www.xici.net/d201420188.htm
http://www.xici.net/d201420185.htm
http://www.xici.net/d201420177.htm
http://www.xici.net/d201420170.htm
http://www.xici.net/d201420166.htm
http://www.xici.net/d201420164.htm
http://www.xici.net/d201420160.htm
http://www.xici.net/d201420151.htm
http://www.xici.net/d201420142.htm
http://www.xici.net/d201420137.htm
http://www.xici.net/d201420132.htm
http://www.xici.net/d201420125.htm
http://www.xici.net/d201420117.htm
http://www.xici.net/d201420114.htm
http://www.xici.net/d201420108.htm
http://www.xici.net/d201420099.htm
http://www.xici.net/d201420096.htm
http://www.xici.net/d201420090.htm
http://www.xici.net/d201420082.htm
http://www.xici.net/d201420079.htm
http://www.xici.net/d201420075.htm
http://www.xici.net/d201420071.htm