而出口未知问题赛过System.DataTable [英] Unknown problem while exporting excel to System.DataTable

查看:167
本文介绍了而出口未知问题赛过System.DataTable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Excel中数据文件数据表。


这里是我的code-片段:

I am trying to get data from Excel File to DataTable.
Here's my code-snippet :

 FilePath = WebConfig.SavePath + "Book2.xls";

            // Create the connection object
            OleDbConnection oledbConn = new OleDbConnection(WebConfig.ExcelConnection(FilePath));
            // Open connection
            oledbConn.Open();

            // Create OleDbCommand object and select data from worksheet Sheet1 //WebConfig.SheetNameFirstExcel
            OleDbCommand cmd = new OleDbCommand("SELECT * FROM [" + "Sheet1" + "$]", oledbConn);

            // Create new OleDbDataAdapter
            OleDbDataAdapter oleda = new OleDbDataAdapter();

            oleda.SelectCommand = cmd;

            // Create a DataSet which will hold the data extracted from the worksheet.
            DataTable dt = new DataTable();

            // Fill the DataSet from the data extracted from the worksheet.
            oleda.Fill(dt);



这个问题是,部分细胞的数据导出到数据表,而另一些则不是。


Excel的格式是这样的:


第一行标题

第二部分的文字

第三排空白

4日起表

的10列&安培; 298行。



什么是缺少上述code,或用于提取这种Excel的任何建议(.xlsx)格式在asp.net 3.5数据表


Problem with this is that, data of some cells is exported to data-table while some other is NOT.
format of excel is something like :
1st Row Heading
2nd Some text
3rd Row blank
4th onwards a table
of 10 columns & 298 rows.

What is missing in above code, or any suggestion for extracting such excel(.xlsx) to datatable in asp.net 3.5

推荐答案

考虑到所有你有我怀疑标准的OLEDB驱动程序就不能读你的Excel文件正确,由于文字的表数据之前,行的问题。

Given all the problems you have I suspect the standard oledb driver just can't read your excel file correctly due to the rows of text prior to the table data.

如何搬走c将其使用这个库 HTTP://epplus.codeplex.com / 读取.xlsx文件创建数据表或数据库记录

How about move away and just code it manually using this library http://epplus.codeplex.com/ for reading the xlsx file and create your datatable or db records

这篇关于而出口未知问题赛过System.DataTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆