以下是表hyjd 从外部excel表导入不重复的数据,为什么只增加了空行,没有任何数据?
excel表结构是这样的
商家 |
车牌 |
卡类 |
入场时间 |
付费时间 |
券号 |
打折类型 |
优惠额度(元) |
备注 |
酒店 |
浙A060HK |
临时卡A |
2020-08-29 22:29:09 |
2020-09-01 02:01:03 |
D9BAAAD7 |
全免 |
75.00 |
停车券20200901 |
酒店 |
苏E96K9H |
临时卡A |
2020-08-31 22:13:07 |
2020-09-01 07:17:32 |
AE024701 |
全免 |
15.00 |
停车券20200901 |
酒店 |
京NH81H9 |
临时卡A |
2020-08-29 21:53:05 |
2020-09-01 08:13:44 |
9BC3FB66 |
全免 |
80.00 |
停车券20200901 |
酒店 |
浙A59Z6V |
临时卡A |
2020-08-31 14:52:56 |
2020-09-01 08:30:46 |
74241D8F |
全免 |
30.00 |
停车券20200901 |
酒店 |
苏MV128T |
临时卡A |
2020-08-31 22:39:16 |
2020-09-01 05:55:23 |
16F4E7C6 |
全免 |
15.00 |
停车券20200901 |
表hyjd结构是一样的,只是后面增加了几列,以后要设置计算公式用,以“券号” qh 作为不重复的标志
此主题相关图片如下:表.png
Dim dlg As New OpenFileDialog
dlg.Filter = "Excel文件|*.xls;*.xlsx"
If dlg.ShowDialog =DialogResult.OK Then
Dim t As Table = Tables("hyjd")
t.StopRedraw()
Dim Book As New XLS.Book(dlg.FileName)
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Dim newcount As Integer = 0
Dim oldcount As Integer = 0
For n As Integer = 1 To Sheet.Rows.Count -1
Dim r As DataRow = t.DataTable.Find("qh = '" & sheet(n, 0).text & "'")
If r Is Nothing Then
r = t.DataTable.AddNew()
newcount += 1
Else
oldcount += 1
End If
For i As Integer = 0 To sheet.Cols.Count -1
Dim cname As String = sheet(0, i).text
If t.Cols.Contains(cname) Then
If t.Cols(cname).IsBoolean Then
If sheet(n, i).Text = 1 OrElse sheet(n, i).Text = "true" Then
r(cname) = True
Else
r(cname) = False
End If
Else
r(cname) = sheet(n, i).Text
End If
End If
Next
Next
msgbox("新增" & newcount & " " & "更新旧数据" & oldcount)
t.ResumeRedraw()
End If
[此贴子已经被作者于2020/9/1 11:20:50编辑过]