Dim dlg As New OpenFileDialog
dlg.Filter = "Excel文件|*.xls;*.xlsx"
If dlg.ShowDialog =DialogResult.OK Then
Dim App As New MSExcel.Application
Dim nms() As String = {"单号"}
Dim nms2() As String = {"单号"}
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 dic2 As new Dictionary(of String, Integer)
For i As Integer = 1 To rg.Columns.Count
dic2.Add(ary(1,i),i)
Next
Dim dic As new Dictionary(of Integer, List(of object))
For Each s As object In ws.Shapes
Dim rng = s.TopLeftCell
Output.Show("rng.Row=" & rng.Row)
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
Output.Show("dic.keys=" & dic.keys.count)
For n As Integer = 2 To rg.Rows.Count
Dim ro As Row = Tables("table_3").AddNew
For Each k As String In dic2.Keys
If Tables("table_3").Cols.Contains(k) AndAlso k <> "图片"
ro(k) = ary(n,dic2(k))
End If
Next
If dic.ContainsKey(n) Then
Dim ls = dic(n)
Output.Show("ls.count=" & ls.count)
Dim line As new List(Of String)
For j As Integer = 0 To ls.count-1
Dim name = ary(n, 1) & "_" & j & ".jpg"
Output.Show("name=" & name)
msgbox(name)
ls(j).copy
ClipBoard.GetImage.save(projectPath & "attachments\" & name)
Output.Show("attachments=" & projectPath & "attachments\" & name)
Dim proc As new Process
Dim ftp1 As New FtpClient
Dim i As Integer = 0
Dim dr As Row = Tables("Table_3").Current
ftp1.host="172.16.120.41"
ftp1.Account ="admin"
ftp1.password ="qw123"
If ftp1.MakeDir(dr("记录时间") & "\") Then
Else
End If
If ftp1.Upload(projectPath & "attachments\" & name) = True Then
msgbox("成功")
Else
msgbox("不成功")
End If
If ftp1.FileExists("\" &dr("记录时间")& "\" & dr("记录时间") & ".jpg") Then
For i = 1 To 999
If ftp1.FileExists("\" &dr("记录时间")& "\" & dr("记录时间")& "("& i &").jpg")=False Then
Exit For
End If
Next
End If
If i > 0 Then
ftp1.Rename(FileSys.GetName(projectPath & "attachments\" & name),"\" &dr("记录时间") & "\" & dr("记录时间") &"("& i &").jpg")
Dim name1 ="\" &dr("记录时间") & "\" & dr("记录时间") &"("& i &").jpg"
ftp1.Delete("/" & FileSys.GetName(projectPath & "attachments\" & name))
Else
ftp1.Rename(FileSys.GetName(projectPath & "attachments\" & name),"\" &dr("记录时间") & "\" & dr("记录时间") &".jpg")
Dim name1="\" &dr("记录时间") & "\" & dr("记录时间") &".jpg"
ftp1.Delete("/" & FileSys.GetName(projectPath & "attachments\" & name))
End If
line.add(name1)
Next
ro.DataRow.lines("图片") = line
Output.Show("line=" & line.count)
End If
Next
app.quit
End If