Dim dlg As New OpenFileDialog
dlg.Filter = "Excel文件|*.xls;*.xlsx"
If dlg.ShowDialog =DialogResult.OK Then
Dim App As New MSExcel.Application
try
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(dlg.FileName)
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
Dim Rg As MSExcel.Range = Ws.UsedRange
Dim ary = rg.value
Dim dic As new Dictionary(of Integer, List(of object))
For Each s As object In ws.Shapes
Dim rng = s.TopLeftCell
If dic.ContainsKey(rng.Row) = False Then
Dim ls As new List(Of object)
ls.add(s)
dic.Add(rng.Row, ls)
Else
dic(rng.Row).add(s)
End If
Next
Dim nms() As String = {"编号","产品","客户","雇员","单价","折扣","数量","日期"}
Dim s1 As new List(of String)
s1.Addrange(nms)
Dim dict As new Dictionary(of String,Integer)
For m As Integer = 1 To rg.Cols.Count
If s1.Contains(ary(0,m)) Then
dict.add(ary(0,m),m)
End If
Next
For n As Integer = 2 To rg.Rows.Count
If DataTables("订单").Find("编号 = \'" & ary(n,dict("编号")) & "\'") Is Nothing Then
Dim ro As Row = Tables("订单").AddNew
For i As Integer = 0 To nms.length - 1
ro(i) = ary(n,dict(nms(i)))
Next
If dic.ContainsKey(n) Then
Dim ls = dic(n)
Dim line As new List(Of String)
For j As Integer = 0 To ls.count-1
Dim name = ary(n, 7) & "_" & j & ".jpg"
ls(j).copy
ClipBoard.GetImage.save(projectPath & "attachments/" & name)
line.add(name)
Next
ro.DataRow.lines("照片") = line
End If
End If
Next
MessageBox.Show("导入成功!","恭喜!")
catch ex As exception
msgbox(ex.message)
MessageBox.Show("导入失败!","恭喜!")
finally
app.quit
End try
End If