#include <GDIPlus.au3>
#include <Misc.au3>
#include <Date.au3>
#include <GUIConstants.au3>
;#include <ServiceControl.au3>
;#include <Excel1.au3>
#include <File.au3>
#include <Array.au3>
#include <Excel.au3>
#include <MsgBoxConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>
#include <Array.au3>
#include <GDIPlus.au3>
#include <Misc.au3>
#include <Date.au3>
#include <GUIConstants.au3>
Opt('MustDeclareVars', 1)
Opt("TrayMenuMode", 1)
Global $MinimalGUI, $DTUser, $DateTime, $Group, $B001Label, $B001, $B001Data, $A001Label, $A001, $A001Data, $ActionPerformedLabel, $ActionPerformed, $ActionPerformedData, $ExplanationLabel, $Explanation, $ExplanationData, $SubmitLog, $nMsg, $LogData, $FullGUI, $FilenameWextensionLabel, $FilenameWextension, $FilenameWextensionData, $Result
Global $IP_Address = @IPAddress1
Global $OS_Version = @OSVersion
Global $UserName = @UserName
; =======================================================================
; Command Line Interpretation
; =======================================================================
If $CmdLine[0] = 0 Then ;gui mode
$FullGUI = GUICreate("Excel Search and Replace Tool v1.0", 640, 500, -1, -1, -1, $WS_EX_ACCEPTFILES)
Global $idFilemenu = GUICtrlCreateMenu("&File")
Global $idExititem = GUICtrlCreateMenuItem("Exit", $idFilemenu)
Global $idHelpmenu = GUICtrlCreateMenu("Help")
Global $idUserGuide = GUICtrlCreateMenuItem("User Guide", $idHelpmenu)
$DTUser = GUICtrlCreateLabel("Approved Username: " & $UserName, 25, 10, 400, 24)
GUICtrlSetFont(-1, 11 * _GDIPlus_GraphicsGetDPIRatio()[0], 600, 0, "Calibri")
$DateTime = GUICtrlCreateLabel(_Now(), 440, 10, 175, 24, $SS_RIGHT)
GUICtrlSetFont(-1, 10 * _GDIPlus_GraphicsGetDPIRatio()[0], 600, 0, "Calibri")
$Group = GUICtrlCreateGroup("Please complete the fields below.", 25, 40, 593, 420)
GUICtrlSetFont(-1, 9 * _GDIPlus_GraphicsGetDPIRatio()[0], 600, 0, "Calibri")
DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($Group), "wstr", 0, "wstr", 0)
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$A001Label = GUICtrlCreateLabel("Finding Word:", 35, 66, 250, 24)
GUICtrlSetFont(-1, 12 * _GDIPlus_GraphicsGetDPIRatio()[0], 400, 0, "Calibri")
$A001 = GUICtrlCreateInput("", 35, 89, 215, 24)
GUICtrlSetFont(-1, 12 * _GDIPlus_GraphicsGetDPIRatio()[0], 400, 0, "Calibri")
$B001Label = GUICtrlCreateLabel("Replace Word:", 260, 66, 200, 24)
GUICtrlSetFont(-1, 12 * _GDIPlus_GraphicsGetDPIRatio()[0], 400, 0, "Calibri")
$B001 = GUICtrlCreateInput("", 260, 89, 180, 24)
GUICtrlSetFont(-1, 12 * _GDIPlus_GraphicsGetDPIRatio()[0], 400, 0, "Calibri")
$FilenameWextensionLabel = GUICtrlCreateLabel("File name/s with extension", 35, 125, 480, 24)
GUICtrlSetFont(-1, 12 * _GDIPlus_GraphicsGetDPIRatio()[0], 400, 0, "Calibri")
$FilenameWextension = GUICtrlCreateEdit("", 35, 150, 575, 155, BitOR($ES_WANTRETURN, $ES_AUTOVSCROLL, $WS_VSCROLL, $ES_MULTILINE))
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlSetFont(-1, 9 * _GDIPlus_GraphicsGetDPIRatio()[0], 400, 0, "Calibri")
GUICtrlSendMsg($FilenameWextension, $EM_LIMITTEXT, -1, 0)
GUICtrlSetFont(-1, 12 * _GDIPlus_GraphicsGetDPIRatio()[0], 400, 0, "Calibri")
$SubmitLog = GUICtrlCreateButton("Execute", 460, 58, 149, 56, $BS_MULTILINE)
GUICtrlSetFont(-1, 14 * _GDIPlus_GraphicsGetDPIRatio()[0], 500, 0, "Calibri")
;GUICtrlSetBkColor($DTUser, 0xFFFFBF) ;For testing
GUICtrlSetBkColor($A001, 0xFFFFBF)
GUICtrlSetBkColor($B001, 0xFFFFBF)
GUICtrlSetBkColor($FilenameWextension, 0xFFFFBF)
;GUICtrlSetBkColor($FilenameWextensionLabel, 0xFFFFBF)
GUICtrlSetBkColor($ActionPerformed, 0xFFFFBF)
GUICtrlSetBkColor($Explanation, 0xFFFFBF)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $SubmitLog
$A001Data = GUICtrlRead($A001)
$B001Data = GUICtrlRead($B001)
$FilenameWextensionData = GUICtrlRead($FilenameWextension)
$ActionPerformedData = GUICtrlRead($ActionPerformed)
$ExplanationData = GUICtrlRead($Explanation)
GUISetState(@SW_SHOW)
$LogData = "Finding Word: "&GUICtrlRead($A001)&@CRLF&"Replace Word: "&GUICtrlRead($B001)& @CRLF&@CRLF& "File Name:" &@CRLF& $FilenameWextensionData & @CRLF
MsgBox(0, "LogData", $LogData)
ProgressOn("Progress Meter", "Increments every second", "0%")
ProgressSet(0, "0%")
FileDelete(@ScriptDir&"\log.txt")
filewrite(@ScriptDir&"\log.txt",$FilenameWextensionData)
ProgressSet(20, "20%")
Local $file11,$line
$file11 = @ScriptDir&"\log.txt"
FileOpen($file11, 0)
For $i = 1 to _FileCountLines($file11)
$line = FileReadLine($file11, $i)
;msgbox(0,'Reading File Name','The File ' & $i & ' is ' & $line)
ProgressSet(30+$i, 30+$i&"%")
Local $path,$pPath
$path= $line
$pPath = StringRegExp($path, "\\([^\\]+)\\*.xls*", 3)
; MsgBox(0, 0, $pPath[0])
; Create application object and open an example workbook
Local $oExcel = _Excel_Open(False)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeReplace Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
Local $oWorkbook = _Excel_BookOpen1($oExcel, $line)
If @error Then
MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeReplace Example", "Error opening workbook '" & $line& @CRLF & "@error = " & @error & ", @extended = " & @extended)
_Excel_Close($oExcel)
Exit
EndIf
; *****************************************************************************
; Find all cells with text "long " and remove it (replace with "")
; *****************************************************************************
;MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeReplace Example 1", "Press OK to modify data in cell 'G1'.")
_Excel_RangeReplace($oWorkbook, Default, Default, GUICtrlRead($A001), GUICtrlRead($A001)&@CRLF&GUICtrlRead($B001))
If _Excel_RangeRead($oWorkbook,default, "G1:G50",2) = "long" Then _ExcelFontSetProperties($oWorkbook, 1, 1, 100, 100, "微软雅黑", True, False, 10, False, 5, 18, 10, "center")
_Excel_BookSaveAs($oWorkbook, @ScriptDir & ""&$pPath[0]&"_"&@YEAR&@MON&@MDAY&"_"&@HOUR&@MIN&@SEC&".xlsx", Default, True)
_Excel_BookClose($oWorkbook,True)
;_Excel_BookSaveAs($oWorkbook, @ScriptDir, $xlHtml, True)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeReplace Example 2", "Error replacing data the range." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
;MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeReplace Example 2", "Replace text to '"&GUICtrlRead($B001) &"'" &@CRLF &@CRLF & " Data successfully replaced.")
Next
ProgressSet(90, "90%")
FileClose($file11)
ProgressSet(100, "Done", "Complete")
Sleep(1000)
; Close the progress window.
ProgressOff()
MsgBox(0,"Message","Done!")
Exit
Case $idUserGuide
MsgBox(0, "Message", "The user guide is not quite ready.")
ContinueLoop
Case $GUI_EVENT_CLOSE, $idExititem
Exit
EndSwitch
WEnd
Else
_Terminate()
EndIf
Func _Excel_BookOpen1($oExcel, $sFilePath, $bReadOnly = Default, $bVisible = Default, $sPassword = Default, $sWritePassword = Default, $bUpdateLinks = Default)
; Error handler, automatic cleanup at end of function
Local $oError = ObjEvent("AutoIt.Error", "__Excel_COMErrFunc")
#forceref $oError
If Not IsObj($oExcel) Or ObjName($oExcel, 1) <> "_Application" Then Return SetError(1, @error, 0)
If Not FileExists($sFilePath) Then Return SetError(2, 0, 0)
If $bReadOnly = Default Then $bReadOnly = False
If $bVisible = Default Then $bVisible = True
Local $oWorkbook = $oExcel.Workbooks.Open($sFilePath, $bUpdateLinks, $bReadOnly, Default, $sPassword, $sWritePassword)
If @error Then Return SetError(3, @error, 0)
Local $oWindow = $oExcel.Windows($oWorkbook.Name) ; <== Modified
If IsObj($oWindow) Then $oWindow.Visible = $bVisible ; <== Modified
; If a read-write workbook was opened read-only then set @extended = 1
If $bReadOnly = False And $oWorkbook.Readonly = True Then Return SetError(0, 1, $oWorkbook)
Return $oWorkbook
EndFunc ;==>_Excel_BookOpen
; #FUNCTION# ====================================================================================================================
; Name ..........: _GDIPlus_GraphicsGetDPIRatio
; Description ...: Get DPI Ratio
; Syntax ........: _GDIPlus_GraphicsGetDPIRatio([$iDPIDef = 96])
; Parameters ....: $iDPIDef - [optional] An integer value. Default is 96.
; Return values .: actual DPI Ratio as Array, or set @error to non zero, also @extended may be set
; Author ........: UEZ
; Modified ......: argumentum 2015.06.05 / better error return
; Remarks .......:
; Related .......:
; Link ..........: https://www.autoitscript.com/forum/topic/166479-writing-dpi-awareness-app-workaround/
; Example .......: yes
; ===============================================================================================================================
Func _GDIPlus_GraphicsGetDPIRatio($iDPIDef = 96)
Local $aResults[2] = [1, 1]
_GDIPlus_Startup()
Local $hGfx = _GDIPlus_GraphicsCreateFromHWND(0)
If @error Then Return SetError(1, @extended, $aResults)
Local $aResult
#forcedef $__g_hGDIPDll, $ghGDIPDll
$aResult = DllCall($__g_hGDIPDll, "int", "GdipGetDpiX", "handle", $hGfx, "float*", 0)
If @error Then Return SetError(2, @error, $aResults)
Local $iDPI = $aResult[2]
Local $aResults[2] = [$iDPIDef / $iDPI, $iDPI / $iDPIDef]
_GDIPlus_GraphicsDispose($hGfx)
_GDIPlus_Shutdown()
Return $aResults
EndFunc ;==>_GDIPlus_GraphicsGetDPIRatio
;Ref https://www.autoitscript.com/forum/topic/165393-get-mac-address-efficiently/
Func GET_MAC($_MACsIP)
Local $_MAC, $_MACSize
Local $_MACi, $_MACs, $_MACr, $_MACiIP
$_MAC = DllStructCreate("byte[6]")
$_MACSize = DllStructCreate("int")
DllStructSetData($_MACSize, 1, 6)
$_MACr = DllCall("Ws2_32.dll", "int", "inet_addr", "str", $_MACsIP)
$_MACiIP = $_MACr[0]
$_MACr = DllCall("iphlpapi.dll", "int", "SendARP", "int", $_MACiIP, "int", 0, "ptr", DllStructGetPtr($_MAC), "ptr", DllStructGetPtr($_MACSize))
$_MACs = ""
For $_MACi = 0 To 5
If $_MACi Then $_MACs = $_MACs & ":"
$_MACs = $_MACs & Hex(DllStructGetData($_MAC, 1, $_MACi + 1), 2)
Next
DllClose($_MAC)
DllClose($_MACSize)
Return $_MACs
EndFunc ;==>GET_MAC
Func _Terminate()
Exit (0)
EndFunc ;==>_Terminate