#include <GuiConstantsEx.au3>
#include <ButtonConstants.au3>
#include <Constants.au3>
#include <EditConstants.au3>
#Include <ACN_String.au3>
#Include <File.au3>
#Include <Array.au3>
#Include <Clipboard.au3>
#Include <Excel.au3>
Opt ('GUIOnEventMode',1)
Global $var_1 = IniRead('Au3_ExcelDiff3.ini', '配置', '数据源1', 'C:\Users\Administrator\Desktop\1')
Global $var_2 = IniRead('Au3_ExcelDiff3.ini', '配置', '数据源2', 'C:\Users\Administrator\Desktop\2')
Global $var_3 = IniRead('Au3_ExcelDiff3.ini', '配置', '日志地址', 'C:\ExcelDiff.log')
;Global $var_4 = IniRead('Au3_ExcelDiff.ini', '配置', '安装目录', 'C:\Program Files\ComponentSoftware\ExcelDiff\ExcelDiff.exe')
Global $var_5 = IniRead('Au3_ExcelDiff3.ini', '配置', '对比列数', '10') ;对比列数
Global $var_6 = IniRead('Au3_ExcelDiff3.ini', '配置', '空白行数', '10') ;空白行数
; GUI
$parent = GuiCreate('批量对比EXCEL v3.0', 400, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, 'SpecialEvents')
GUISetOnEvent($GUI_EVENT_MINIMIZE, 'SpecialEvents')
GUISetOnEvent($GUI_EVENT_RESTORE, 'SpecialEvents')
$Label_0 = GuiCtrlCreateLabel('输入要对比的文件夹:', 10, 16)
$Label_1 = GuiCtrlCreateLabel('数据源1:', 10, 45)
$source_1 = GUICtrlCreateInput ( $var_1, 65 , 41 , 260 )
$Button_1 = GuiCtrlCreateButton('选择', 333, 39 , 60)
GUICtrlSetOnEvent(-1, 'Choose_Source_1_Pressed')
$Label_2 = GuiCtrlCreateLabel('数据源2:', 10, 75)
$source_2 = GUICtrlCreateInput ( $var_2, 65 , 71 , 260 )
$Button_2 = GuiCtrlCreateButton('选择', 333, 69 , 60)
GUICtrlSetOnEvent(-1, 'Choose_Source_2_Pressed')
$Label_3 = GuiCtrlCreateLabel('日志保存路径:', 10, 105)
$LogLocation = GUICtrlCreateInput ( $var_3, 10 , 125 , 315 )
$Button_3 = GuiCtrlCreateButton('选择', 333, 123 , 60)
GUICtrlSetOnEvent(-1, 'Choose_LogLocation_Pressed')
$Label_5 = GuiCtrlCreateLabel('需要对比的列数:', 10, 210, 100) ;GUICtrlCreateLabel ( "文本", 左侧, 顶部 [, 宽度 [, 高度 [, 样式 [, 扩展样式]]]] )
$iColumn = GUICtrlCreateInput ( $var_5, 110 , 206 , 25) ;GUICtrlCreateInput ( "文本", 左侧, 顶部 [, 宽度 [, 高度 [, 样式 [, 扩展样式]]]] )
$Label_6 = GuiCtrlCreateLabel('连续空白', 10, 235, 50)
$iRowBlank = GUICtrlCreateInput ( $var_6, 60 , 231 , 25 )
$Label_7 = GuiCtrlCreateLabel('行算文件结束', 90, 235)
$Button_8 = GuiCtrlCreateButton('直接对比', 240, 260 , 150 ) ;GUICtrlCreateButton ( "文本", 左侧, 顶部 [, 宽度 [, 高度 [, 样式 [, 扩展样式]]]] )
GUICtrlSetOnEvent(-1, 'Run_Pressed2')
Func Choose_Source_1_Pressed()
$var_1 = FileSelectFolder('选择数据源1文件夹:', '')
GUICtrlSetData ( $source_1, $var_1 )
EndFunc ;==>Choose_Source_1_Pressed
Func Choose_Source_2_Pressed()
$var_2 = FileSelectFolder('选择数据源2文件夹:', '')
GUICtrlSetData ( $source_2, $var_2 )
EndFunc ;==>Choose_Source_2_Pressed
Func Choose_LogLocation_Pressed()
$var_3 = FileSelectFolder('选择日志保存路径:', '')
If StringRight($var_3, 1) = '\' Then $var_3 = StringTrimRight($var_3, 1)
GUICtrlSetData ( $LogLocation, $var_3 & '\ExcelDiff.log' )
EndFunc ;==>Choose_LogLocation_Pressed
Func Run_Pressed2()
WinSetState ( '批量对比EXCEL v3.0', '输入要对比的文件夹:', @SW_MINIMIZE )
;获取数据源1文件夹中的文件列表
Global $FileList1=_FileListToArray($var_1,'*',1)
If @Error=1 Then
MsgBox (0,"","数据源1文件夹不存在!")
Exit
EndIf
If @Error=4 Then
MsgBox (0,"","数据源1文件不存在!")
Exit
EndIf
;_ArrayDisplay($FileList1,"$FileList1")
;获取数据源2文件夹中的文件列表
Global $FileList2=_FileListToArray($var_2,'*',1)
If @Error=1 Then
MsgBox (0,"","数据源2文件夹不存在!")
Exit
EndIf
If @Error=4 Then
MsgBox (0,"","数据源2文件不存在!")
Exit
EndIf
;_ArrayDisplay($FileList2,"$FileList2")
;获取同名文件列表并对比文件
Global $t_item1[$FileList1[0]]
For $i = 1 To $FileList1[0]
$file1 = $var_1 & '\' & $FileList1[$i]
$file2 = $var_2 & '\' & $FileList1[$i]
If FileExists($var_2 & '\' & $FileList1[$i]) Then
$str1 = $file1 &@CRLF& $file2 &@CRLF& $var_5 &@CRLF& $var_6 &@CRLF& $var_3 &@CRLF& $var_1 ;;调试
MsgBox(0,'',$str1) ;;调试
$sFilePath1 = 'C:\Users\Administrator\Desktop\1\1.xls'
$sFilePath2 = 'C:\Users\Administrator\Desktop\2\1.xls'
$iColumn = 10
$iRowBlank = 10
$LogLocation = 'C:\ExcelDiff.log'
$source_1 = 'C:\Users\Administrator\Desktop\1'
$str2 = $sFilePath1 &@CRLF& $sFilePath2 &@CRLF& $iColumn &@CRLF& $iRowBlank &@CRLF& $LogLocation &@CRLF& $source_1 ;;调试
MsgBox(0,'',$str2) ;;调试
If StringCompare($str1,$str2) = 0 Then MsgBox(0,'','ok') ;;调试
;_ExcelDiff( $sFilePath1, $sFilePath2, $iColumn, $iRowBlank, $LogLocation, $source_1 ) ;这个就可以
_ExcelDiff( $file1, $file2, $var_5, $var_6, $var_3, $var_1 ) ;这个就不行
;调用直接对比脚本
;Call ( '_ExcelDiff' , $file1, $file2, $var_5, $var_6, $var_3, $var_1 )
Else
EndIf
Next
Global $t_item2[$FileList2[0]]
For $i = 1 To $FileList2[0]
If not FileExists($var_1 & '\' & $FileList2[$i]) Then
EndIf
Next
WinSetState ( '批量对比EXCEL v3.0', '输入要对比的文件夹:', @SW_RESTORE )
EndFunc ;==>Run_Pressed2
Func _ExcelDiff( $sFilePath1, $sFilePath2, $iColumn, $iRowBlank, $LogLocation, $source_1 )
$oExcel1= _ExcelBookOpen( $sFilePath1 , 0 , True ) ;True为只读模式。0为不可见,1为可见。
$oExcel2= _ExcelBookOpen( $sFilePath2 , 0 , True )
For $i=1 to _CountRow($oExcel1, $iRowBlank)
$aArray1 = _ExcelReadArray($oExcel1, $i, 1, $iColumn, 0)
$aArray2 = _ExcelReadArray($oExcel2, $i, 1, $iColumn, 0)
_ArrayDisplay($aArray1,'$aArray1') ;;调试
$str1 = _ArrayToString($aArray1, @TAB)
$str2 = _ArrayToString($aArray2, @TAB)
MsgBox(0,'','$str1:' & $str1) ;;调试
MsgBox(0,'','$str2:' & $str2) ;;调试
$a = StringLen ( $source_1 ) +1
$filename = StringTrimLeft ( $sFilePath1, $a )
If StringCompare($str1, $str2) = 0 Then
Else
$Same = 0
MsgBox(0,'','不同的行:' & $i & @CRLF & $str1 & @CRLF & $str2) ;;调试
EndIf
Next
_ExcelBookClose($oExcel1)
_ExcelBookClose($oExcel2)
EndFunc
;~计算Excel有效行数,误差<$iRowBlank
Func _CountRow($oExcel,$iRowBlank)
$sRow = 1
While 1
$n = 0
For $i = 1 to $iRowBlank
$sCellvalue = _ExcelReadCell($oExcel, $sRow , 1) ;~读取第一列的单元格内容
If $sCellvalue = '' Then $n = $n + 1
$sRow = $sRow + 1
Next
If $n = $iRowBlank Then
Return $sRow - $iRowBlank -1
Exit
EndIf
WEnd
EndFunc
; SpecialEvents
Func SpecialEvents()
Select
Case @GUI_CtrlId = $GUI_EVENT_CLOSE
Exit
Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE
Case @GUI_CtrlId = $GUI_EVENT_RESTORE
EndSelect
EndFunc ;==>SpecialEvents
; GUI MESSAGE LOOP
GuiSetState()
While GuiGetMsg() <> $GUI_EVENT_CLOSE
WEnd