想把表格(多头表格)导出后写入数据,然后再导入时出现问题,表头被导入,且数据没有被导人。
导出代码:
Dim dcb As WinForm.ComboBox = e.Form.Controls("ComboBox2")
Dim tbl As Table = Tables(""& dcb.text &"")
Dim hdr As Integer = tbl.HeaderRows '获得表头的层数
Dim cnt As Integer
Dim Book As New XLS.Book
Dim Sheet As XLS.Sheet = Book.Sheets(0)
tbl.CreateSheetHeader(Sheet) '生成表头
For c As Integer = 0 To tbl.Cols.Count - 1
If tbl.Cols(c).Visible Then
For r As Integer = 0 To tbl.Rows.Count - 1
sheet(r + hdr,cnt).value = tbl(r,c)
Next
cnt = cnt + 1
End If
Next
Book.Save("d:\记录表\test.xls")
Dim Proc As New Process
Proc.File = "d:\记录表\test.xls"
Proc.Start()
导入代码:Dim dlg As New OpenFileDialog '定义一个新的OpenFileDialog
dlg.Filter= "Excel文件|*.xls|2007Excel文件|*.xls" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
MessageBox.Show("你选择的是:" & dlg.FileName,"提示") '提示用户选择的文件
Dim drb As WinForm.ComboBox = e.Form.Controls("ComboBox3")
Dim sx1 As WinForm.ComboBox = e.Form.Controls("ComboBox5")
Dim csxm1 As WinForm.ComboBox = e.Form.Controls("ComboBox7")
DataTables(""& drb.text &"").DeleteFor("竞赛名称 like '*" & sx1.text & "*' And 参赛项目 like '*" & csxm1.text & "*'")
Dim mg As New Merger
mg.SourcePath = dlg.FileName
mg.Format = "excel" '指定格式
mg.SourceTableName = "sheet1$"
mg.DataTableName = ""& drb.text &""
mg.Merge()
End If
请专家指教!