C#导入Excel数据时的一个BUG
2011-01-26 13:27
525 查看
在进行SQL数据导入时无法将第二行和第五行的value值导入,图示粘贴不过来,所以进行口述,大致情况是:
第二行和第五行的value值是数字型,而其他几行的value是字符型。
经过在网上查找和实际操作检验,最终找到了一个解决办法:
1、在连接Excel的Oledb串中加上
IMEX=1,使得 Excel
表格中混合列(即该列中的包含有多种类型的数据)被
ADO.NET 认为其数据类型是 String
。如果某列的数据全部都是一种类型,如数字型,那么 ADO.NET
仍然认为该是列的类型是其数据的类型。
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/MyExcel.xls;Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"""
"HDR=Yes;" indicates that the first row contains columnnames, not data
"IMEX=1;" tells the driver to always read "intermixed" data columns as text
TIP! SQL syntax: "SELECT * FROM [sheet1$]" - i.e. worksheet name followed by a "$" and wrapped in "[" "]" brackets.
2、修改注册表键值。
[HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Jet/4.0/Engines/Excel]
located registry REG_DWORD "TypeGuessRows". That's the key to not letting Excel use only the first 8 rows to guess the columns data type. Set this value to 0 to scan all rows. This might hurt
performance.
TypeGuessRows:修改为0。(检索所有行)
第二行和第五行的value值是数字型,而其他几行的value是字符型。
经过在网上查找和实际操作检验,最终找到了一个解决办法:
1、在连接Excel的Oledb串中加上
IMEX=1,使得 Excel
表格中混合列(即该列中的包含有多种类型的数据)被
ADO.NET 认为其数据类型是 String
。如果某列的数据全部都是一种类型,如数字型,那么 ADO.NET
仍然认为该是列的类型是其数据的类型。
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/MyExcel.xls;Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"""
"HDR=Yes;" indicates that the first row contains columnnames, not data
"IMEX=1;" tells the driver to always read "intermixed" data columns as text
TIP! SQL syntax: "SELECT * FROM [sheet1$]" - i.e. worksheet name followed by a "$" and wrapped in "[" "]" brackets.
2、修改注册表键值。
[HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Jet/4.0/Engines/Excel]
located registry REG_DWORD "TypeGuessRows". That's the key to not letting Excel use only the first 8 rows to guess the columns data type. Set this value to 0 to scan all rows. This might hurt
performance.
TypeGuessRows:修改为0。(检索所有行)
相关文章推荐
- c# .Net :Excel NPOI导入导出操作教程之数据库表信息数据导出到一个Excel文件并写到磁盘示例分享
- c# .Net :Excel NPOI导入导出操作教程之List集合的数据写到一个Excel文件并导出
- 发布一个Excel导入数据到GridView的类
- c#将Excel数据导入到数据库的实现代码
- C# 实现 Excel文件的数据导入
- C# web 读取excel并导入数据库
- 效率最高的Excel数据导入---(c#调用SSIS Package将数据库数据导入到Excel文件中【附源代码下载】)
- C#实现EXCEL数据的导入导出
- 一个小例子集合xlrd,matplotlib,numpy,scipy使用方法(从Excel导入数据)
- C# 导入Excel遇到数字字母混合列数据丢失解决
- 使用C#导入导出数据到Excel
- C#将EXCEL数据导入到数据库示例
- 效率最高的Excel数据导入---(c#调用SSIS Package将数据库数据导入到Excel文件中【附源代码下载】)
- asp.net/c#代码实现excel to mssql数据导入
- C#将SQL数据库中数据导入Excel中,并将Excel中反导入SQL数据库中
- c#将Excel数据导入到数据库的实现代码
- C#将SQL数据库中数据导入Excel中,并将Excel中反导入SQL数据库中
- C#将Excel数据表导入SQL数据库的两种方法
- 20160308 C#代码实现Excel数据导入到SQL Server数据库中
- C#如何从Excel里面导入数据