如题!
我想做的功能如下,比如:
Excel中的Sheet1有一列 ID
1
2
5
6
……
100
现在我想读取Excel中的ID列,作为 Select * from Table where ID in (1,2,5,6,……100) 中 ID in () 里面的条件,最后把Select出来的数据再输出Excel !
(ID列是可变的,每次的数据都不同)
请问怎么做呢?能否给点例子
Regards
急急急,,在线等~~~~~~~~~
...全文
6399打赏收藏
急~~~~~怎么在.net中读取Excel某一列的值 ?
如题! 我想做的功能如下,比如: Excel中的Sheet1有一列 ID 1 2 5 6 …… 100 现在我想读取Excel中的ID列,作为 Select * from Table where ID in (1,2,5,6,……100) 中 ID in () 里面的条件,最后把Select出来的数据再输出Excel ! (ID列是可变的,每次的数据都不同) 请问怎么做呢?能否给点例子 Regards 急急急,,在线等~~~~~~~~~
说说自己的意见,不知道是否可行
Dim strConn As String
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\com.xls;Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"""
Dim conn As New OleDb.OleDbConnection(strConn)
Dim myCommand As New OleDb.OleDbDataAdapter("SELECT ID FROM [Sheet1$]", strConn)
引用:bianchen(未来风)
说说自己的意见,不知道是否可行
Dim strConn As String
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\com.xls;Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"""
Dim conn As New OleDb.OleDbConnection(strConn)
Dim myCommand As New OleDb.OleDbDataAdapter("SELECT ID FROM [Sheet1$]", strConn)
接下来
dim dataset1 as dataset
myCommand .fill(dataset1,"tb")
dim datatable1 as datatable
dtbl1= dataset1.table("tb") '只是excel 的ID字段建立的一个表
同样你建立一个所有excel数据的表,假如为dtbl2
for i as integer = 0 to dtbl1.rows.count -1
for j as integer = 0 to dtbl2.rows.count -2
if dtbl1.rows(i).item("ID") = dtlb2.rows(i).item("ID")
再建立一个listview ,例子如下,
至于listview怎么导入到数据库中就不要我说了
Dim strSEQ As String = myReader.Tables("TBL").Rows(i).Item(0).ToString.Trim
Dim strPID As String = myReader.Tables("TBL").Rows(i).Item(1).ToString.Trim
Dim strPName As String = myReader.Tables("TBL").Rows(i).Item(2).ToString.Trim
Dim strDRUG As String = myReader.Tables("TBL").Rows(i).Item(3).ToString.Trim
Dim strOPTime As String = CutYear(myReader.Tables("TBL").Rows(i).Item(4).ToString).Trim
Dim strDepart As String = myReader.Tables("TBL").Rows(i).Item(5).ToString.Trim
Dim strDocName As String = myReader.Tables("TBL").Rows(i).Item(6).ToString.Trim
Dim Item = New ListViewItem(New String() {strSEQ, strPID, strPName, strDRUG, strOPTime, strDepart, strDocName}, 0)