Dim dlg As New OpenFileDialog '定义一个新的OpenFileDialog
dlg.Filter= "Excel文件|*.xlsx" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
MessageBox.Show("你选择的是:" & dlg.FileName,"提示") '提示用户选择的文件
Dim Str1 As String = dlg.FileName
Dim fx As String
If Str1 > "" AndAlso Str1.Contains("返修") Then
fx = "返修单"
End If
Dim khmc As String
khmc = FileSys.GetName(dlg.FileName).SubString(0,3)
Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(dlg.FileName)
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
Dim Rg1 As MSExcel.Range
Dim rowsmax As Integer = 0
Dim colmax As Integer = 0
Dim x As String
Dim y As String
Dim x0 As String
Dim y0 As String
Dim x1 As String
Dim y1 As String
Dim x2 As String
Dim y2 As String
Dim x3 As String
Dim y3 As String
Dim x4 As String
Dim y4 As String
Dim chrq As String
Dim rg = Ws.UsedRange
For i As Integer =1 To rg.Columns.count
Dim r = ws.cells(1000,i).End(MsExcel.XlDirection.xlUp).Row
If r > RowsMax Then
RowsMax = r
End If
Next
For i As Integer = 1 To rowsMax
Dim r = ws.cells(i,200).End(MsExcel.XLDirection.xlToLeft).Column
If r > ColMax Then
ColMax = r
End If
Next
For i As Integer = 1 To RowsMax
For j As Integer = 1 To ColMax
Rg1 = Ws.Cells(i,j)
If Rg1.text = "箱号" Then
x = i
y = j
End If
Next
Next
For j As Integer = 1 To ColMax
Rg1 = Ws.Cells(x,j)
If Rg1.text = "颜色" Then
x3 = x
y3 = j
End If
Next
For j As Integer = 1 To ColMax
Rg1 = Ws.Cells(x,j)
If Rg1.text = "合计" Then
x4 = x
y4 = j
End If
Next
For i As Integer = 1 To RowsMax
For j As Integer = 1 To ColMax
Rg1 = Ws.Cells(i,j)
If Rg1.text = "本次出货" Then
x0 = i
y0 = j
End If
Next
Next
For i As Integer = 1 To RowsMax
For j As Integer = 1 To ColMax
Rg1 = Ws.Cells(i,j)
If Rg1.text = "总计:" Then
x1 = i
y1 = j
End If
Next
Next
For i As Integer = 1 To RowsMax
For j As Integer = 1 To ColMax
Rg1 = Ws.Cells(i,j)
If Rg1.text.Contains("出货日期") Then
x2 = i
y2 = j
Dim chr As String
chr = Ws.Cells(i,j).Value.SubString(5).Trim(" ").Replace("/","-")
Dim Day As Date = chr
chrq = Format(Day,"d")
End If
Next
Next
Dim tbl As New DataTableBuilder("临时箱单")
Dim Lst As New List(Of String)
Dim nms() As String
With tbl
For j As Integer = y To y0
Rg1 = Ws.Cells(x,j)
Dim bt As String = Rg1.text.Trim(" ")
tbl.AddDef(bt, Gettype(String), 32)
Lst.Add(bt)
Next
nms = Lst.ToArray() '将集合转换为数组
End With
tbl.Build()
MainTable= Tables("表A")
Dim Book As New XLS.Book(dlg.FileName)
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Tables("临时箱单").StopRedraw()
For n As Integer = x To x1-2
Dim r As Row = Tables("临时箱单").AddNew()
For m As Integer = 0 To nms.Length - 1
r(nms(m)) = Sheet(n,m).Value
Next
Next
Tables("临时箱单").ResumeRedraw()
Dim dtb As New DataTableBuilder("临时出货明细")
dtb.AddDef("箱号", Gettype(String), 4)
dtb.AddDef("品类", Gettype(String), 10)
dtb.AddDef("款号", Gettype(String), 10)
dtb.AddDef("颜色", Gettype(String), 10)
dtb.AddDef("规格", Gettype(String), 10)
dtb.AddDef("数量", Gettype(Double))
dtb.AddDef("出货日期", Gettype(String), 15)
dtb.Build()