以下这段代码可以合并带空格的excel表格,当接收表有数据时,可以正常运行。但是当接收表为空时,则会出现错误提示(见下图)。如何达到接收表为空时能够正常运行,请各位老师指教,谢谢!!
Dim Sheet As XLS.Sheet = Book.Sheets(i)
For r As Integer = 1 To Sheet.Rows.Count - 1
Dim Filter1 As String = ""
For c As Integer = 0 To Sheet.Cols.Count - 1
If c > 0 Then
Filter1 = Filter1 & " And "
End If
If sheet(r,c).Value <> "" AndAlso CurrentTable.DataTable.DataCols(sheet(0,c).Value).IsNumeric Then
Filter1 = Filter1 & sheet(0,c).Value & " = " & sheet(r,c).Value
ElseIf sheet(r,c).Value = "" Then
Filter1 = Filter1 & sheet(0,c).Value & " is null "
Else
Filter1 = Filter1 & sheet(0,c).Value & " = '" & sheet(r,c).Value & "'"
End If
Next
If CurrentTable.DataTable.Find(Filter1) Is Nothing Then
Dim dr As Row = CurrentTable.AddNew()
For c As Integer = 0 To Sheet.Cols.Count - 1
dr(Sheet(0,c).Value) = Sheet(r,c).Value
Next
End If
Next

此主题相关图片如下:r.jpg

[此贴子已经被作者于2012-11-10 16:59:00编辑过]