Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 01/19/2016 in all areas

  1. I translated and added some parameters to this function from Delphi sources on the web. Function supports 1D and 2D arrays. All array's data are converted to String datatype. This function doesn't depend on installed Microsoft Excel!! _ArrayToXLS(Const ByRef $avArray, $sFileName[, $Transpose = False[, $iStartRow = 0[, $iEndRow = 0[, $iStartCol = 0[, $iEndCol = 0]]]]]) Here it is also with simple example: #include <File.au3> #include <WinAPI.au3> Dim $myArray[6] = ['A','B','C','D','E','F'] _ArrayToXLS($myArray, @ScriptDir & '\test1.xls') _ArrayToXLS($myArray, @ScriptDir & '\test1t.xls', True) ; transpose _ArrayToXLS($myArray, @ScriptDir & '\test1x.xls', False, 2, 4) ; C,D,E _ArrayToXLS($myArray, @ScriptDir & '\test1xt.xls', True, 2, 4) ; C,D,E transposed Dim $myArray[2][3] = [['A','B','C'], ['D','E','F']] _ArrayToXLS($myArray, @ScriptDir & '\test2.xls') _ArrayToXLS($myArray, @ScriptDir & '\test2t.xls', True) ; transpose _ArrayToXLS($myArray, @ScriptDir & '\test2x.xls', False, 1, 1) ; second row: D,E,F _ArrayToXLS($myArray, @ScriptDir & '\test2xt.xls', True, 1, 1) ; second row: D,E,F transposed _ArrayToXLS($myArray, @ScriptDir & '\test2y.xls', False, 0, 0, 1, 2) ; B,C + E,F _ArrayToXLS($myArray, @ScriptDir & '\test2yt.xls', True, 0, 0, 1, 2) ; B,C + E,F transposed $myArray = _FileListToArray(@ScriptDir, '*', 1) _ArrayToXLS($myArray, @ScriptDir & '\test3.xls') _ArrayToXLS($myArray, @ScriptDir & '\test3x.xls', False, 1) ; skip first row (contains number of files) ShellExecute(@ScriptDir & "\test3x.xls") ; #FUNCTION# ==================================================================================================================== ; Name...........: _ArrayToXLS ; Description ...: Places the elements of an 1D or 2D array into an Excel file (XLS). ; Syntax.........: _ArrayToXLS(Const ByRef $avArray, $sFileName[, $Transpose = False[, $iStartRow = 0[, $iEndRow = 0[, $iStartCol = 0[, $iEndCol = 0]]]]]) ; Parameters ....: $avArray - Array to save ; $sFileName - Full path to XLS file ; $Transpose - [optional] At 2D array changes rows and columns ; $iStartRow - [optional] Zero based index (row) of array to start saving at ; $iEndRow - [optional] Zero based index (row) of array to stop saving at, if zero then last row is taken ; $iStartCol - [optional] Zero based index (column) of array to start saving at ; $iEndCol - [optional] Zero based index (column) of array to stop saving at, if zero then last column is taken ; Return values .: Success - 1 ; Failure - 0, sets @error: ; |1 - $avArray is not an array ; |2 - $avArray is not 1D/2D array ; |3 - $iStartRow is greater than $iEndRow ; |4 - $iStartCol is greater than $iEndCol ; |5 - couldn't create XLS file ; Author ........: Zedna ; Modified.......: ; Remarks .......: Function supports 1D and 2D arrays. All array's data are converted to String datatype. ; This function doesn't depend on installed Microsoft Excel. ; Related .......: _ArrayToString, _ArrayToClip ; Link ..........; ; Example .......; Yes ; =============================================================================================================================== Func _ArrayToXLS(Const ByRef $avArray, $FileName, $Transpose = False, $iStartRow = 0, $iEndRow = 0, $iStartCol = 0, $iEndCol = 0) Local $nBytes If Not IsArray($avArray) Then SetError(1, 0, 0) $iDimension = UBound($avArray, 0) If $iDimension > 2 Then SetError(2, 0, 0) $iUBound1 = UBound($avArray, 1) - 1 If $iEndRow < 1 Or $iEndRow > $iUBound1 Then $iEndRow = $iUBound1 If $iStartRow < 0 Then $iStartRow = 0 If $iStartRow > $iEndRow Then Return SetError(3, 0, 0) If $iDimension = 2 Then $iUBound2 = UBound($avArray, 2) - 1 If $iEndCol < 1 Or $iEndCol > $iUBound2 Then $iEndCol = $iUBound2 If $iStartCol < 0 Then $iStartCol = 0 If $iStartCol > $iEndCol Then Return SetError(4, 0, 0) EndIf $hFile = _WinAPI_CreateFile($FileName, 1) If @error Then Return SetError(5, 0, 0) $str_bof = DllStructCreate('short;short;short;short;short;short') DllStructSetData($str_bof, 1, 0x809) DllStructSetData($str_bof, 2, 0x8) DllStructSetData($str_bof, 3, 0x0) DllStructSetData($str_bof, 4, 0x10) DllStructSetData($str_bof, 5, 0x0) DllStructSetData($str_bof, 6, 0x0) _WinAPI_WriteFile($hFile, DLLStructGetPtr($str_bof), DllStructGetSize($str_bof), $nBytes) Switch $iDimension Case 1 ; 1D array For $i = $iStartRow To $iEndRow ; 0 To $iUBound1 If $Transpose Then __XLSWriteCell($hFile, 0, $i - $iStartRow, $avArray[$i]) Else __XLSWriteCell($hFile, $i - $iStartRow, 0, $avArray[$i]) EndIf Next Case 2 ; 2D array For $i = $iStartRow To $iEndRow ; 0 To $iUBound1 For $j = $iStartCol To $iEndCol ; 0 To $iUBound2 If $Transpose Then __XLSWriteCell($hFile, $j - $iStartCol, $i - $iStartRow, $avArray[$i][$j]) Else __XLSWriteCell($hFile, $i - $iStartRow, $j - $iStartCol, $avArray[$i][$j]) EndIf Next Next EndSwitch $str_eof = DllStructCreate('short;short') DllStructSetData($str_eof, 1, 0x0A) DllStructSetData($str_eof, 2, 0x0) _WinAPI_WriteFile($hFile, DLLStructGetPtr($str_eof), DllStructGetSize($str_eof), $nBytes) _WinAPI_CloseHandle($hFile) Return 1 EndFunc ; ==> _ArrayToXLS ; internal helper function for _ArrayToXLS() Func __XLSWriteCell($hFile, $Row, $Col, $Value) Local $nBytes $Value = String($Value) $Len = StringLen($Value) $str_cell = DllStructCreate('short;short;short;short;short;short') DllStructSetData($str_cell, 1, 0x204) DllStructSetData($str_cell, 2, 8 + $Len) DllStructSetData($str_cell, 3, $Row) DllStructSetData($str_cell, 4, $Col) DllStructSetData($str_cell, 5, 0x0) DllStructSetData($str_cell, 6, $Len) _WinAPI_WriteFile($hFile, DLLStructGetPtr($str_cell), DllStructGetSize($str_cell), $nBytes) $tBuffer = DLLStructCreate("byte[" & $Len & "]") DLLStructSetData($tBuffer, 1, $Value) _WinAPI_WriteFile($hFile, DLLStructGetPtr($tBuffer), $Len, $nBytes) EndFunc ; ==> __XLSWriteCell EDIT: Here is original Delphi source http://programujte.com/forum/vlakno/5645-jak-na-exel/ procedure XlsWriteCellLabel(XlsStream: TStream; const ACol, ARow: Word; const AValue: string); var L: Word; const {$J+} CXlsLabel: array[0..5] of Word = ($204, 0, 0, 0, 0, 0); {$J-} begin L := Length(AValue); CXlsLabel[1] := 8 + L; CXlsLabel[2] := ARow; CXlsLabel[3] := ACol; CXlsLabel[5] := L; XlsStream.WriteBuffer(CXlsLabel, SizeOf(CXlsLabel)); XlsStream.WriteBuffer(Pointer(AValue)^, L); end; function SaveAsExcelFile(AGrid: TStringGrid; AFileName: string): Boolean; const {$J+} CXlsBof: array[0..5] of Word = ($809, 8, 00, $10, 0, 0); {$J-} CXlsEof: array[0..1] of Word = ($0A, 00); var FStream: TFileStream; I, J: Integer; begin Result := False; FStream := TFileStream.Create(PChar(AFileName), fmCreate or fmOpenWrite); try CXlsBof[4] := 0; FStream.WriteBuffer(CXlsBof, SizeOf(CXlsBof)); for i := 0 to AGrid.ColCount - 1 do for j := 0 to AGrid.RowCount - 1 do XlsWriteCellLabel(FStream, I, J, AGrid.cells[i, j]); FStream.WriteBuffer(CXlsEof, SizeOf(CXlsEof)); Result := True; finally FStream.Free; end; end; and here is link to more general Delphi code where is handled also writing integer/decimal datatypes. http://kurapaty.blogspot.com/2008/01/creating-excel-xls-from-delphi.html EDIT2: Here is link to topic in Examples for generating XML XLS (XLSX) without Excel installed from Jerome EDIT3: Here is link to topic in Examples for reading Excel data using SQL (ADO) without Excel installed from ptrex EDIT4: Very nice description of Excel x ADO in Delphi Accessing and managing MS Excel sheets with Delphi http://delphi.about.com/od/database/l/aa090903a.htm EDIT5: There is only one issue with XLS files generated this way: Badly formated national characters in cells when opened by Open Office/Libre Office. Inside binary XLS file and also when opened by Microsoft Excel it's OK. So I think it' some bug (maybe some bad autodetection of code page?) of Open Office/Libre Office. EDIT6: There is problem in MS Excel with data in cells bigger than 255 chars. For data > 255 chars Excel loads XLS file without errors but these cells are empty. This 255 chars problem isn't in LibreOffice (version 3.4.1) only in Microsoft Excel. See post #14, #15 for details
    1 point
  2. Lately, in this forum, there were many questions and problems referring to the use of ie.au3 UDF using the latest version of AutoIt v3.3.14.x. I would like to present the correct usage of the UDF. I hope that it will help many users to prevent problems. #include <ie.au3> #include <MsgBoxConstants.au3> ; STEP 1 ; YOU MUST SET ANY COM ERROR HANDLER IN ONE OF THE FOLLOWING WAY ; STEP 1: CASE 1 ; you should set COM Error Handler Function for ie.au3 UDF _IEErrorHandlerRegister(_User_ErrFunc) ; STEP 1: CASE 2 ; eventually if you not want to recieve additional information ; you can use just the same function without parameter ; _IEErrorHandlerRegister() ; STEP 1: CASE 3 ; or use your own global COM Error Handler ;~ Global $oCOMErrorHandler = ObjEvent("AutoIt.Error", _User_ErrFunc) ; STEP 2 ; if you do not wish to get in Console Output Pane information like the following: ; --> IE.au3 T3.0-2 Error from function _IEAction(click), $_IESTATUS_InvalidDataType ; You can uncomment this following line: ; _IEErrorNotify(False) _Example() Func _Example() ; First lets create some IE Object Local $oIE = _IECreate('google.com') ; you should always check for @error in any function (even you own made) If @error Then MsgBox($MB_ICONERROR, '_IECreate', '@error = ' & @error & @CRLF & '@extended = ' & @extended) ; Set @error when you return from function with Failure Return SetError(1,0,0) Endif ; here we try to get reference to LuckyStrike button Local $oLuckyStrike = _IEGetObjByName($oIE, 'btnI') ; you should always check for @error in any function (even you own made) If @error Then MsgBox($MB_ICONERROR, '_IEGetObjByName', '@error = ' & @error & @CRLF & '@extended = ' & @extended) ; Set @error when you return from function with Failure Return SetError(2,0,0) Endif ; here we try to click LuckyStrike button with previously achieved Object which is a reference to HTML DOM OBJECT in IE Instance _IEAction($oLuckyStrike, 'click') ; you should wait when page is loading _IELoadWait($oIE) ; some user interaction If MsgBox($MB_YESNO, 'Question', 'Do you want to back ?') = $IDYES Then _IEAction($oIE, 'back') EndIf EndFunc ;==>_Example ; User's COM error function. ; After SetUp with ObjEvent("AutoIt.Error", ....) will be called if COM error occurs Func _User_ErrFunc($oError) ; Do anything here. ConsoleWrite(@ScriptFullPath & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _ @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _ @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _ @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _ @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF) EndFunc ;==>_User_ErrFunc Regards, mLipok
    1 point
  3. In one cases I was need to check each frames , as there was different documents. Each document is loaded separate.
    1 point
  4. Then you could only check for the existance of an object that, if it is loaded, tells you that the page has fully loaded.
    1 point
  5. Zedna

    How to edit our GUI script

    I have the same (last) version of Koda and I have FUUL path in all my AU3 scripts. So try to add full path to your form and try "Update Script" again ...
    1 point
  6. 1 point
  7. now, suppose you want to install your scheduled task into a subfolder. that way it will be visible to the user only if the "Task Scheduler Library" branch is expanded, so it is visually segregated from users' tasks - same way Microsoft do with their phenomenal list of tasks (some 88 tasks in 58 folders...). the trick is to prefix the task name with the subfolder, e.g. au3\au3@task instead of just au3@task as in the example above, for the task to be placed in the au3 subfolder. also, don't forget to remove it at uninstall. so this is the updated setup script: #RequireAdmin #AutoIt3Wrapper_Res_Fileversion=0.0.1.0 #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_UseX64=y #NoTrayIcon #include <MsgBoxConstants.au3> Global $sTitle = 'au3@task Setup' Global $sDrive = StringLeft(@WindowsDir, 3) Global $sTaskDir = 'au3' Global $sTaskName = 'au3@task' Global $sTaskFullName = $sTaskDir & '\' & $sTaskName If AlreadyInstalled() Then If MsgBox($MB_ICONQUESTION + $MB_YESNO, $sTitle, 'Uninstall? ') = $IDYES Then If Uninstall() Then MsgBox($MB_ICONINFORMATION, $sTitle, 'Uninstallation completed successfully. ') Else MsgBox($MB_ICONERROR, $sTitle, 'Uninstallation error. ') EndIf Else MsgBox($MB_ICONINFORMATION, $sTitle, 'Uninstallation aborted. ') EndIf Else If MsgBox($MB_ICONQUESTION + $MB_YESNO, $sTitle, 'Install? ') = $IDYES Then If Install() Then If MsgBox($MB_ICONQUESTION + $MB_YESNO, $sTitle, 'Installation completed successfully. Run task now? ') = $IDYES Then If RunWait('schtasks.exe /Run /TN ' & $sTaskFullName, '', @SW_HIDE) = 0 Then MsgBox($MB_ICONINFORMATION, $sTitle, 'Task is running. ') Else MsgBox($MB_ICONERROR, $sTitle, 'Error running the task. ') EndIf Else MsgBox($MB_ICONINFORMATION, $sTitle, 'Done. ') EndIf Else MsgBox($MB_ICONERROR, $sTitle, 'Installation error. ') EndIf Else MsgBox($MB_ICONINFORMATION, $sTitle, 'Installation aborted. ') EndIf EndIf Func AlreadyInstalled() If Not FileExists($sDrive & 'au3@task.exe') Then Return False If RunWait('schtasks.exe /Query /TN ' & $sTaskFullName, '', @SW_HIDE) <> 0 Then Return False Return True EndFunc ;==>AlreadyInstalled Func Install() If Not FileInstall('au3@task.exe', $sDrive, 1) Then Return False Local $sXML = _ '<?xml version="1.0" encoding="UTF-16"?>' & @CRLF & _ '<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">' & @CRLF & _ ' <Triggers>' & @CRLF & _ ' <BootTrigger>' & @CRLF & _ ' <Enabled>true</Enabled>' & @CRLF & _ ' </BootTrigger>' & @CRLF & _ ' </Triggers>' & @CRLF & _ ' <Principals>' & @CRLF & _ ' <Principal id="Author">' & @CRLF & _ ' <UserId>S-1-5-18</UserId>' & @CRLF & _ ' <RunLevel>HighestAvailable</RunLevel>' & @CRLF & _ ' </Principal>' & @CRLF & _ ' </Principals>' & @CRLF & _ ' <Settings>' & @CRLF & _ ' <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>' & @CRLF & _ ' <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>' & @CRLF & _ ' <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>' & @CRLF & _ ' <AllowHardTerminate>false</AllowHardTerminate>' & @CRLF & _ ' <StartWhenAvailable>false</StartWhenAvailable>' & @CRLF & _ ' <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>' & @CRLF & _ ' <IdleSettings>' & @CRLF & _ ' <StopOnIdleEnd>true</StopOnIdleEnd>' & @CRLF & _ ' <RestartOnIdle>false</RestartOnIdle>' & @CRLF & _ ' </IdleSettings>' & @CRLF & _ ' <AllowStartOnDemand>true</AllowStartOnDemand>' & @CRLF & _ ' <Enabled>true</Enabled>' & @CRLF & _ ' <Hidden>false</Hidden>' & @CRLF & _ ' <RunOnlyIfIdle>false</RunOnlyIfIdle>' & @CRLF & _ ' <WakeToRun>false</WakeToRun>' & @CRLF & _ ' <ExecutionTimeLimit>PT0S</ExecutionTimeLimit>' & @CRLF & _ ' <Priority>7</Priority>' & @CRLF & _ ' </Settings>' & @CRLF & _ ' <Actions Context="Author">' & @CRLF & _ ' <Exec>' & @CRLF & _ ' <Command>ExePath</Command>' & @CRLF & _ ' </Exec>' & @CRLF & _ ' </Actions>' & @CRLF & _ '</Task>' $sXML = StringReplace($sXML, 'ExePath', $sDrive & 'au3@task.exe') Local $sFileXML = @TempDir & '\au3@task.xml' FileDelete($sFileXML) FileWrite($sFileXML, $sXML) If FileRead($sFileXML) <> $sXML Then Return False If RunWait('schtasks.exe /Create /XML "' & $sFileXML & '" /TN ' & $sTaskFullName, '', @SW_HIDE) <> 0 Then Return False FileDelete($sFileXML) Return True EndFunc ;==>Install Func Uninstall() RunWait('schtasks.exe /End /TN ' & $sTaskFullName, '', @SW_HIDE) If RunWait('schtasks.exe /Delete /F /TN ' & $sTaskFullName, '', @SW_HIDE) <> 0 Then Return False Sleep(3000) If Not FileDelete($sDrive & 'au3@task.exe') Then Return False DirRemove(@SystemDir & '\Tasks\' & $sTaskDir) ; remove the folder only if empty Return True EndFunc ;==>Uninstall Note: $sTaskDir can be set to an empty string for not using a subfolder.
    1 point
  8. spudw2k

    tcp ip over internet

    Agreed, your WAN facing router will need to be configured to do port forwarding. That will allow an external address/port to properly connect to the NAT'd device on your internal network. You can even declare that particular ports forward to alternative ports on the internal LAN. For example, a port forward can be setup to allow an incoming connection on external_ip:2424 to redirect to internal_ip:65432
    1 point
  9. JohnOne

    tcp ip over internet

    Forward your ports.
    1 point
×
×
  • Create New...