|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 |
public
static void
InputUserFromExcel(string
filePath) { string
FileExName = filePath.Substring(filePath.LastIndexOf(".") + 1); string
mystring = "Provider = Microsoft.ACE.OLEDB.12.0 ; Data Source =‘"
+ filePath + "‘;Extended Properties =‘Excel 12.0;HDR=YES;IMEX=1‘"; if
(FileExName == "xls") { mystring = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source =‘"
+ filePath + "‘;Extended Properties=Excel 8.0"; } OleDbConnection cnnxls = new
OleDbConnection(mystring); cnnxls.Open(); OleDbDataAdapter myDa = new
OleDbDataAdapter("select * from [pos_260$]", cnnxls); DataSet ZLDs = new
DataSet(); myDa.Fill(ZLDs); Console.Write(ZLDs.Tables[0].Rows.Count); Console.Read(); } } |
原文:http://www.cnblogs.com/wangzhenghua/p/3622679.html