;#include <array.au3>
$file=FileOpenDialog("请选择数据文件:",@MyDocumentsDir&"","Excel文件 (*.xls?;*.xls)",4)
If @error Then Exit 0
Dim $result[5][1]
If StringInStr($file,"|")>0 Then
$arr=StringSplit($file,"|",2)
For $n=1 To UBound($arr)-1
$arr[$n]=$arr[0]&""&$arr[$n]
Next
Else
Dim $arr[2]
$arr[1]=$file
EndIf
;_ArrayDisplay($arr)
$result[0][0]="柜号"
$result[1][0]="卸船"
$result[2][0]="拆箱/返空"
$result[3][0]="装箱/提柜"
$result[4][0]="堆存期"
$excel=ObjCreate("excel.application")
$excel.visible=False
$excel.displayalerts=False
For $n=1 To UBound($arr)-1
If FileExists($arr[$n]) Then
$t=UBound($result,2)
ReDim $result[5][$t+1]
$wb=$excel.workbooks.open($arr[$n])
$rng=0
With $wb.activesheet
$result[0][$t]=.range("d7").value
$rng=.cells.find("卸船")
If IsObj($rng) Then $result[1][$t]=.range("J"&$rng.row).formula
$rng=0
$rng=.cells.find("拆箱")
If IsObj($rng) Then
$result[2][$t]=.range("J"&$rng.row).formula
Else
$rng=0
$rng=.cells.find("收返空箱")
If IsObj($rng) Then
$result[2][$t]=.range("J"&$rng.row).formula
Else
$rng=0
$rng=.cells.find("收返重箱")
If IsObj($rng) Then
$result[2][$t]=.range("J"&$rng.row).formula
Else
$rng=0
$rng=.cells.find("装船")
If IsObj($rng) Then
$result[2][$t]=.range("J"&$rng.row).formula
Else
$result[2][$t]="NoDatas"
EndIf
EndIf
EndIf
EndIf
$rng=0
$rng=.cells.find("装箱")
If IsObj($rng) Then
$result[3][$t]=.range("J"&$rng.row).formula
Else
$rng=0
$rng=.cells.find("提箱返重")
If IsObj($rng) Then
$result[3][$t]=.range("J"&$rng.row).formula
Else
$result[3][$t]="NoDatas"
EndIf
EndIf
If $result[2][$t]<>"NoDatas" And $result[3][$t]<>"NoDatas" Then $result[4][$t]=Round(Number($result[3][$t])-Number($result[2][$t]),0)
EndWith
$wb.close(False)
EndIf
Next
;_ArrayDisplay($result)
$excel.visible=True
$wb=$excel.workbooks.add
With $wb.activesheet
.columns("B:D").numberformatlocal="yyyy-m-d hh:mm"
For $n=0 To UBound($result)-1
For $i=0 To UBound($result,2)-1
.cells($i+1,$n+1)=$result[$n][$i]
Next
Next
.columns.autofit
EndWith
$excel.displayalerts=True
$wb=0
$excel=0
结果不一定是正确的,不过方法就是这样的,试下 |