Excel18位数字类型转换C#类型

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值