按老师提示 当前代码完善如下 还是会报错!
当前是部分表成功导入数据 部分表没有导入
提示错误:
无法在 System.Double 和 System.String 上执行“=”操作。
Dim cm2 As WinForm.ComboBox = e.Form.Controls("ComboBox2")
Dim prb As WinForm.ProgressBar = e.Form.Controls("ProgressBar1")
Dim r As Row
Dim i,j As Integer
Dim t1,t2 As Table
Dim str1,str2 As String
Dim str As String
If cm2.Text="" Then
MessageBox.Show("请先选择要接收的数据表,然后再进行文件选择.字段匹配.数据导入操作!","温馨提示")
Else
Dim c4 As WinForm.ComboBox = e.Form.Controls("ComboBox4")
If c4.text <>"" Then
Dim b1 As String= "1:" & c4.text
With e.Form
Dim dlg As New OpenFileDialog
dlg.Filter= "Excel 97-2003文件(*.xls)|*.xls|Excel 2007文件(*.xlsx)|*.xlsx"
If dlg.ShowDialog = DialogResult.Ok Then
For Each File As String In FileSys.GetFiles(FileSys.GetParentPath(dlg.FileName))
Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(File)
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
Dim Rg As MSExcel.Range = Ws.Rows(b1) '选定多行
Rg.EntireRow.Delete(MSExcel.XlDirection.xlToLeft) '右面的单元格左移
App.Visible = False
If cm2.text="台账明细表" Then
Dim Rg1 As MSExcel.Range = Ws.Cells(1,8)
Rg1.Value = "谈话开始时间"
Dim Rg2 As MSExcel.Range = Ws.Cells(1,9)
Rg2.Value = "谈话结束时间"
End If
If Wb.WorkSheets(1).name ="Sheet" Then
Wb.WorkSheets(1).name = "台账明细表"
End If
Dim t11 As String =Format(Date.Now,"yyyyMMddhhmmss")
Dim dz As String = FileSys.GetParentPath(File) & "\" & t11 & FileSys.GetName(File)
Wb.SaveAs(dz)
wb.close
app.quit
.Controls("TextBox1").value = FileSys.GetParentPath(dlg.FileName)
Dim dc1 As Col
t1 = Tables(cm2.Text)
t2 = e.form.Controls("Table1").Table
Dim nms1 As String
Dim nms11 As String
Dim cnt1 As Integer = DataTables(cm2.Text).DataCols.Count
Dim Book As New XLS.Book(dz)
Dim Sheet As XLS.Sheet = Book.Sheets(0)
t2.StopRedraw
t2.DataTable.DataRows.clear
Dim zd1 As New Dictionary(Of Integer, String)
For i = 0 To Sheet.Cols.count - 1
If Sheet(0,i).text > ""
r = t2.AddNew()
r("来源字段") = Sheet(0,i).Value
r("来源列数")=i
zd1.Add(r("来源列数"),r("来源字段"))
End If
Next
For Each dc1 In t1.cols
nms1 = nms1 & "|" & dc1.name
t2.cols("接收字段").ComboList = nms1
Next
t2.ResumeRedraw
str1 = e.form.Controls("TextBox1").value
str2 = e.form.Controls("combobox3").value
If str1 = "" Then
Return
End If
For j = 0 To Sheet.Cols.count - 1
If t1.cols.Contains(Sheet(0,j).value) Then
If str = "" Then
str = Sheet(0,j).value
str = str.Replace(" ", "").Trim
Else
str = str & "," & Sheet(0,j).value
str = str.Replace(" ", "").Trim
End If
End If
Next
Dim dr As DataRow
For i = 1 To Sheet.Rows.Count -1
Dim sss As String = ""
prb.Visible = True
prb.Maximum = Sheet.Rows.Count - 1
For Each r In Tables(cm2.Text).Rows
For j = 0 To str.split(",").Length - 1
If sss > "" Then sss = sss & " and "
MessageBox.Show(t2.Rows(j)("来源列数"))
sss = sss & str.split(",")(j) & "='" & Sheet(i,t2.Rows(j)("来源列数")).Value & "'"
Next
Next
dr = DataTables(cm2.Text).find(sss)
If dr Is Nothing Then
r = t1.AddNew()
For j = 0 To str.split(",").Length - 1
r(str.split(",")(j)) = Sheet(i,t2.Rows(j)("来源列数")).Value
Next
t1.DataTable.save
End If
Next
Next
prb.Value = i
MessageBox.Show("数据导入完毕!","温馨提示!")
End If
End With
End If
End If