求助,怎样读取Excel表格中的数据能高效一些?
假设Excel文件的路径为:
string path = "D:\salary.xls";
逐行读取该表格中第6行至最后一行的数据,每行读取第2列至第8列的数据,怎么写呢?
------解决方案--------------------用ado.net
ExcelODBC标准"Driver={Microsoft Excel Driver (*.xls)}; DriverId=790; Dbq=C:\MyExcel.xls; DefaultDir=c:\mypath; "OLE DB标准"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.
------解决方案--------------------使用OleDbDataReader读取; 给你个简单的列子
select * from [sheet1&2-8] sheet1是excel第一个工作薄 2-8是指 第二行到第八行
select * from [sheet1&B-Z] B-D是指 B列到Z列 忘记是符号&还是$了 具体的自己试试!