感觉楼主的代码好像太啰嗦了一点
这样的效果似乎一样
Datatables("导入临时表").datarows.clear()
tables("导入临时表").StopRedraw
Dim cmd As New SQLCommand
cmd.ConnectionName = "baox"
Dim dlg As New OpenFileDialog '定一个新的OpenFileDialog
dim f1,c1,r1 as string
dlg.Filter= "Excel文件|*.xls" '|文本文件|*.txt|Access文件|*.mdb" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
If dlg.FileName <> " " then
Dim Book As New XLS.Book(dlg.FileName)
Dim Sheet As XLS.Sheet = Book.Sheets(0)
dim i as integer
dim num,num1,num2,ss1 as string
Dim Values(),ss as String
For k as integer = 1 to Sheet.Rows.Count -1
dim r as row = tables("导入临时表").AddNew()
For p as integer = 0 to Sheet.Cols.Count -1
dim colname as string = Sheet(0,p).Value
dim colvalue as string = Sheet(k,p).Value
if colname = "规格" Then
r("规格") = colvalue
if colvalue IsNot nothing then
Dim Values1() as String
Values1 = colvalue.split("*")
r("厚度") = Values1(0)
if Values1.Length > 1 then
r("宽度") = Values1(1)
end if
if Values1.Length > 2 then
r("长度") = Values1(2)
end if
end if
Else
r(colname) = colvalue
end if
Next
Next
end if
end if
tables("导入临时表").ResumeRedraw
tables("导入临时表").sort = "货主代号"
[此贴子已经被作者于2010-7-7 0:17:20编辑过]