帮助:
其中有个例子,如果存在相同编号的订单,则覆盖原来的订单,否则新增一个订单,代码为:
Dim Book As New XLS.Book("c:\test\订单.xls")
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Tables("订单").StopRedraw()
Dim nms() As String = {"编号","产品","客户","雇员","单价","折扣","数量","日期"}
For n As Integer = 1 To Sheet.Rows.Count -1
Dim bh As String = sheet(n,0).Text
Dim dr As DataRow = DataTables("订单").Find("编号 = '" & bh & "'")
If dr Is Nothing Then '如果不存在同编号的订单
dr = DataTables("订单").AddNew()
End If
For m As Integer = 0 To nms.Length - 1
dr(nms(m)) = Sheet(n,m).Value
Next
Next
Tables("订单").ResumeRedraw()
如果要改为:如果编号为空,不执行操作,如果存在相同编号的订单,则覆盖原来的订单,否则新增一个订单,代码稍作调整即可:
Dim Book As New XLS.Book("c:\test\订单.xls")
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Tables("订单").StopRedraw()
Dim nms() As String = {"编号","产品","客户","雇员","单价","折扣","数量","日期"}
For n As Integer = 1 To Sheet.Rows.Count -1
Dim bh As String = sheet(n,0).Text
if bn = "" Then
Continue for
End if
Dim dr As DataRow = DataTables("订单").Find("编号 = '" & bh & "'")
If dr Is Nothing Then '如果不存在同编号的订单
dr = DataTables("订单").AddNew()
End If
For m As Integer = 0 To nms.Length - 1
dr(nms(m)) = Sheet(n,m).Value
Next
Next
Tables("订单").ResumeRedraw()
代码并不复杂,自己体会消化。
[此贴子已经被作者于2019/10/9 22:37:41编辑过]