Jump to content

jerome

Active Members
  • Posts

    35
  • Joined

  • Last visited

About jerome

  • Birthday 04/14/1967

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

jerome's Achievements

Seeker

Seeker (1/7)

1

Reputation

  1. Hi, It's a long time I have posted this, I even forgot it because of the lack of interrest here... Nice to see it helps. There is a lot of things to enhance in this module... Feel free to modify it and share it back here ! Have a nice day Jerome DERN
  2. Hi all, I'm back with an Excel file generation UDF that can manage multi-sheet workbook but without the need to have Excel installed on the computer... You can add more functions if you want but keep always my name in the post of greetings. ;---------------------------------------------------------------------------------------------- ; Copyright Jerome DERN 2010 ; --------------------------------------------------------------------------------------------- #Include <File.au3> ; Const for cell format Const $XMLXLS_STRING = "String" Const $XMLXLS_NUMBER = "Number" Const $XMLXLS_SDATE = "Short Date" Const $XMLXLS_PERCENT = "Percent" Const $XMLXLS_SCIENTIFIC= "Scientific" Const $XMLXLS_DATE = "[$-F400]h:mm:ss\ AM/PM" Const $XMLXLS_FRACTION = "#&quot; &quot;?/?" Const $XMLXLS_COMPTAB = "_-* #,##0.00\ &quot;€&quot;_-;\-* #,##0.00\ &quot;€&quot;_-;_-* &quot;-&quot;??\ &quot;€&quot;_-;_-@_-" ; Constants for cell alignment Const $XMLXLS_CENTER = "Center" Const $XMLXLS_RIGHT = "Right" Const $XMLXLS_LEFT = "Left" Const $XMLXLS_BOTTOM = "Bottom" Const $XMLXLS_TOP = "Top" Const $XMLXLS_JUSTIFIED = "Justify" ; Font style Global Enum Step *2 $XMLXLS_BOLD, $XMLXLS_ITALIC, $XMLXLS_STRIKETHROUGH, $XMLXLS_UNDERLINE, $XMLXLS_SUBSCRIPT, $XMLXLS_SUPERSCRIPT ; BitOr Values for border Global Enum Step *2 $XMLXLS_BDRIGHT, $XMLXLS_BDLEFT, $XMLXLS_BDTOP, $XMLXLS_BDBOTTOM, $XMLXLS_BDCROSS1, $XMLXLS_BDCROSS2 ; Page Set up Const $XMLXLS_LANDSCAPE = "Landscape" Const $XMLXLS_PORTRAIT = "Portrait" $demo1 = True $file = FileOpen("text.xls", 2) ; Create Workbook, active sheet will be se second one (2) _XLSCreateWorkbook($file, 2) ; Define styles _XLSCreateStyles($file) ; Define a new personal style _XLSAddStyle($file, "Header", "Arial", 11, $XMLXLS_BOLD, "000000", "", $XMLXLS_CENTER, $XMLXLS_CENTER, BitOR($XMLXLS_BDRIGHT, $XMLXLS_BDLEFT, $XMLXLS_BDTOP, $XMLXLS_BDBOTTOM)) _XLSAddStyle($file, "Table", "Arial", 11, 0, "000000", "", $XMLXLS_LEFT, $XMLXLS_CENTER, BitOR($XMLXLS_BDRIGHT, $XMLXLS_BDLEFT, $XMLXLS_BDTOP, $XMLXLS_BDBOTTOM)) ; Finish style definition _XLSCloseStyles($file) ; In demo1 case the sheets are generated from an array in memory ; limitation: named area can't be defined If $demo1 Then ; a typical excel sheet memory reservation (can be adjusted to real need) Dim $Sheet1[65536][255] Dim $Sheet2[65536][255] ; Create sheet 1 _XLSInitSheet($Sheet1, "Page 1") _XLSSetRowHeight($Sheet1, 1, 40) _XLSSetColumnWidth($Sheet1, 1, 100) _XLSSetColumnWidth($Sheet1, 2, 110) _XLSSetColumnWidth($Sheet1, 3, 120) _XLSSetCell($Sheet1, 1, 1, "Qty", "", "", "Header") _XLSSetCell($Sheet1, 1, 2, "Value", "", "", "Header") _XLSSetCell($Sheet1, 1, 3, "Total", "", "", "Header") _XLSSetCell($Sheet1, 2, 1, 2, "", $XMLXLS_NUMBER, "Table", "qty") _XLSSetCell($Sheet1, 2, 2, 4, "", $XMLXLS_NUMBER, "Table", "value") ;_XLSSetCell($Sheet1, 2, 3, 0, "RC[-2]*RC[-1]", $XMLXLS_NUMBER, "Table") _XLSSetCell($Sheet1, 2, 3, 0, "qty*value", $XMLXLS_NUMBER, "Table") _XLSGenerateFromArray($file, $Sheet1, $XMLXLS_LANDSCAPE) ; Create sheet 2 _XLSInitSheet($Sheet2, "Page 2") _XLSSetCell($Sheet2, 1, 1, "Name", "", "", "Header") _XLSSetCell($Sheet2, 1, 2, "Value", "", "", "Header") _XLSSetCell($Sheet2, 2, 1, "Beer", "", $XMLXLS_STRING, "Table") _XLSSetCell($Sheet2, 2, 2, 4.0, "", $XMLXLS_NUMBER, "Table") _XLSGenerateFromArray($file, $Sheet2) Else ; in this demo, sheets are generated from direct commands to library ; Create a new worksheet _XLSAddWorkSheet($file, "Sheet1") ; Define specific names of this sheet (optional) _XLSCreateWSNames($file) ; Print area is a specific name for printing zone _XLSAddWSName($file, "Print_Area", "Sheet1!R1C1:R65535C255") ; Finish definition of names _XLSCloseWSNames($file) ; Start Worksheet content _XLSStartWSDefinition($file) ; Create a row _XLSAddRowInWorkSheet($file) ; Add data to first row, column 1 _XLSAddCellInRow($file, "C1", "", $XMLXLS_STRING, "Table") ; Add data to first row, column 2 _XLSAddCellInRow($file, "C2", "", $XMLXLS_STRING) ; Finish row definition _XLSCloseRow($file) ; Create a new row (2nd one) _XLSAddRowInWorkSheet($file) ; Add data to second row, column 1 _XLSAddCellInRow($file, "1", "", $XMLXLS_NUMBER) ; Add data to second row, column 2 _XLSAddCellInRow($file, "2", "RC[-1]*2", $XMLXLS_NUMBER) ; Finish row definition _XLSCloseRow($file) ; Close Worksheet content _XLSCloseWorkSheet($file, $XMLXLS_PORTRAIT, 1, 1, 1, 1, 0.5, 0.5) ; Add a second Worksheet _XLSAddWorkSheet($file, "Sheet2") _XLSStartWSDefinition($file) ; Create first row definition _XLSAddRowInWorkSheet($file) ; Add data to first row, column 1 _XLSAddCellInRow($file, "CC1", "", $XMLXLS_STRING) ; Add data to first row, column 2 _XLSAddCellInRow($file, "CC2", "", $XMLXLS_STRING) ; Finish row definition _XLSCloseRow($file) ; Close Worksheet content _XLSCloseWorkSheet($file) EndIf ; Close Worksbook content, file is ready to use _XLSCloseWorkBook($file) ShellExecute("text.xls") ; ------------------------------------------------------------------------------------------------------------------------------------- ; ------------------------------------------------------- ARRAY TO XML PRIMITIVES ----------------------------------------------------- ; ------------------------------------------------------------------------------------------------------------------------------------- ; ----------------------------------------------------------------------------------- ; Initialize sheet : Set sheet name and set active size to 1 cell ; ----------------------------------------------------------------------------------- Func _XLSInitSheet(ByRef $array, $name) ; $array[0][0] store the name of the sheet;the maximum row number used;the maximum column number used $array[0][0] = $name & ";1;1" EndFunc ; ----------------------------------------------------------------------------------- ; Set row height ; ----------------------------------------------------------------------------------- Func _XLSSetRowHeight(ByRef $array, $row, $height) ; array[x][0] store the height of each row $array[$row][0] = $height EndFunc Func _XLSSetColumnWidth(ByRef $array, $col, $width) ; array[0][x] store the width of each column $array[0][$col] = $width EndFunc ; ------------------------------------------------------------------------------------ ; This format a cell in case of an array usage + generation with _XLSGenerateFromArray function ; ------------------------------------------------------------------------------------ Func _XLSSetCell(ByRef $array, $row, $col, $data, $formulae, $type=$XMLXLS_STRING, $style="Default", $name="") Local $decode If $formulae<>"" Then $data="" if $type = "" Then $type = $XMLXLS_STRING If $style = "" Then $style = "Default" $array[$row][$col] = $data & @CR & $formulae & @CR & $type & @CR & $style & @CR & $name ; check if max of row and column are to be updated $decode = StringSplit($array[0][0], ";") If $decode[0]<3 Then Return If $row>$decode[2] Then $decode[2]=$row If $col>$decode[3] Then $decode[3]=$col $array[0][0]=$decode[1]&";"&$decode[2]&";"&$decode[3] EndFunc ; ---------------------------------------------------------------------------------- ; Generate a sheet from a 2D array. array[0][0] has the sheet name, other array[row][col] ; are strings formatted using _XLSBuildCell function ; ---------------------------------------------------------------------------------- Func _XLSGenerateFromArray($file, ByRef $array, $orientation=$XMLXLS_PORTRAIT, $mbottom = 0.98, $mleft=0.78, $mright=0.78, $mtop=0.98, $hmargin=0.5, $fmargin=0.5) Local $col, $row, $sname, $decode, $data, $formula, $type, $style, $name, $height ; get array real size $decode = StringSplit($array[0][0], ";") If $decode[0] < 3 Then Return $sname = $decode[1] $maxrow = $decode[2] $maxcol = $decode[3] ; Create a new worksheet _XLSAddWorkSheet($file, $sname) ; Define specific names of this sheet (optional) _XLSCreateWSNames($file) ; Print area is a specific name for printing zone _XLSAddWSName($file, "Print_Area", "'"&$sname&"'" & "!R1C1:R"&$maxrow&"C"&$maxcol) ; Small patch in order to Manage here named cells Local $temp = $file, $nbnames=0 Dim $cellnames[1000][2] $file =_TempFile() ; Finish definition of names _XLSCloseWSNames($file) ; Start Worksheet content _XLSStartWSDefinition($file) ; Write column size if needed For $col=1 to $maxcol If $array[0][$col] <> "" Then _XLSColumnSize($file, $col, $array[0][$col]) Next ; generate sheet content For $row=1 to $maxrow $height = -1 If $array[$row][0] <> "" Then $height = $array[$row][0] ; Create a row _XLSAddRowInWorkSheet($file, $height) For $col=1 to $maxcol $data = "" $formula = "" $type = $XMLXLS_STRING $style = "Default" $name = "" If $array[$row][$col]<>"" Then $e = StringSplit($array[$row][$col], @CR) If $e[0]=5 Then $data = $e[1] $formula = $e[2] $type = $e[3] $style = $e[4] $name = $e[5] ;, named cell not yet implemented If $name<>"" Then $cellnames[$nbnames][0] = $name $cellnames[$nbnames][1] = "'"&$sname&"'"&"!R"&$row&"C"&$col $nbnames+=1 EndIf EndIf EndIf If $type="" Then $type = $XMLXLS_STRING If $style="" Then $style = "Default" ; Add data to first row, column 1 _XLSAddCellInRow($file, $data, $formula, $type, $style) Next ; Finish row definition _XLSCloseRow($file) Next ; Add named cell found For $col=1 to $nbnames _XLSAddWSName($temp, $cellnames[$col-1][0], $cellnames[$col-1][1]) Next ; merge files Dim $aRecords _FileReadToArray($file,$aRecords) FileDelete($file) $file = $temp For $col = 1 to $aRecords[0] FileWriteLine($file, $aRecords[$col]) Next ; Close Worksheet content _XLSCloseWorkSheet($file, $orientation, $mbottom, $mleft, $mright, $mtop, $hmargin, $fmargin) EndFunc ; ------------------------------------------------------------------------------------------------------------------------------------- ; ------------------------------------------------------- XML BASE PRIMITIVES --------------------------------------------------------- ; ------------------------------------------------------------------------------------------------------------------------------------- ; -------------------------------------------------------------------------------------------------- ; Create (Define) a new Excel workbook ; -------------------------------------------------------------------------------------------------- Func _XLSCreateWorkbook($file, $activesheet=1) If IsString($file) Then FileDelete($file) $activesheet -= 1 FileWriteLine($file, '<?xml version="1.0"?>') FileWriteLine($file, '<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40">') FileWriteLine($file, '<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office"><Author>XLSXMLGenerator</Author><Created>'&@YEAR&'-'&@MON&'-'&@MDAY&'T'&@HOUR&':'&@MIN&':'&@SEC&'</Created><Company>XLSXML</Company></DocumentProperties>') FileWriteLine($file, '<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel"><ActiveSheet>'&$activesheet&'</ActiveSheet></ExcelWorkbook>') EndFunc ; -------------------------------------------------------------------------------------------------- ; Create (Define) a Style section ; -------------------------------------------------------------------------------------------------- Func _XLSCreateStyles($file) FileWriteLine($file, ' <Styles>') FileWriteLine($file, ' <Style ss:ID="Default" ss:Name="Normal"><Alignment ss:Vertical="Bottom"/><Borders/><Font ss:Size="11"/></Style>') EndFunc ; -------------------------------------------------------------------------------------------------- ; Create (Define) a new style. Borders must be constructed with BitOR() of desired border attribute ; -------------------------------------------------------------------------------------------------- Func _XLSAddStyle($file, $name="S21", $font="Arial", $size=11, $fstyle=0, $pcolor="000000", $icolor="", $AlignHor=$XMLXLS_CENTER, $AlignVer=$XMLXLS_BOTTOM, $Border=0) Local $f, $fontfam="Swiss" FileWriteLine($file, ' <Style ss:ID="' & $name &'">') FileWriteLine($file, ' <Alignment ss:Horizontal="' & $AlignHor & '" ss:Vertical="' & $AlignVer &'"/>') ;$Border = BitOR($XMLXLS_BDRIGHT, $XMLXLS_BDLEFT, $XMLXLS_BDTOP, $XMLXLS_BDBOTTOM, $XMLXLS_BDCROSS1, $XMLXLS_BDCROSS2) If $Border>0 Then FileWriteLine($file, ' <Borders>') If BitAnd($Border, $XMLXLS_BDBOTTOM)>0 Then FileWriteLine($file, ' <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>') If BitAnd($Border, $XMLXLS_BDLEFT)>0 Then FileWriteLine($file, ' <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>') If BitAnd($Border, $XMLXLS_BDRIGHT)>0 Then FileWriteLine($file, ' <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>') If BitAnd($Border, $XMLXLS_BDTOP)>0 Then FileWriteLine($file, ' <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>') If BitAnd($Border, $XMLXLS_BDCROSS1)>0 Then FileWriteLine($file, ' <Border ss:Position="DiagonalLeft" ss:LineStyle="Continuous" ss:Weight="1"/>') If BitAnd($Border, $XMLXLS_BDCROSS2)>0 Then FileWriteLine($file, ' <Border ss:Position="DiagonalRight" ss:LineStyle="Continuous" ss:Weight="1"/>') If $Border>0 Then FileWriteLine($file, ' </Borders>') $f = ' <Font ss:FontName="' & $font & '" x:Family="' & $fontfam & '" ss:Size="' & $size & '" ' ;$fstyle = BitOR($XMLXLS_BOLD, $XMLXLS_ITALIC, $XMLXLS_STRIKETHROUGH, $XMLXLS_UNDERLINE, $XMLXLS_SUBSCRIPT) If BitAnd($fstyle, $XMLXLS_BOLD)>0 Then $f &= 'ss:Bold="1" ' If BitAnd($fstyle, $XMLXLS_ITALIC)>0 Then $f &= 'ss:Italic="1" ' If BitAnd($fstyle, $XMLXLS_STRIKETHROUGH)>0 Then $f &= 'ss:StrikeThrough="1" ' If BitAnd($fstyle, $XMLXLS_UNDERLINE)>0 Then $f &= 'ss:Underline="Single" ' If BitAnd($fstyle, $XMLXLS_SUBSCRIPT)>0 Then $f &= 'ss:VerticalAlign="Subscript" ' If BitAnd($fstyle, $XMLXLS_SUPERSCRIPT)>0 Then $f &= 'ss:VerticalAlign="Superscript" ' If $pcolor <>"" Then $f &= 'ss:Color="#'&$pcolor&'" ' $f &= '/>' If $icolor<>"" Then FileWriteLine($file, '<Interior ss:Color="#'&$icolor&'" ss:Pattern="Solid"/>') FileWriteLine($file, $f) FileWriteLine($file, ' </Style>') EndFunc ; -------------------------------------------------------------------------------------------------- ; Close styles definitions ; -------------------------------------------------------------------------------------------------- Func _XLSCloseStyles($file) FileWriteLine($file, ' </Styles>') EndFunc ; -------------------------------------------------------------------------------------------------- ; Create (Define) a new Excel worksheet ; -------------------------------------------------------------------------------------------------- Func _XLSAddWorkSheet($file, $sheet) FileWriteLine($file, ' <Worksheet ss:Name="' & $sheet & '">') EndFunc ; -------------------------------------------------------------------------------------------------- ; Create (Define) an range named section ; -------------------------------------------------------------------------------------------------- Func _XLSCreateWSNames($file) FileWriteLine($file, ' <Names>') EndFunc ; -------------------------------------------------------------------------------------------------- ; Create (Define) a new range name ; -------------------------------------------------------------------------------------------------- Func _XLSAddWSName($file, $name="Print_Area", $location="'Sheet1'!R1C1:R65535C255") FileWriteLine($file, ' <NamedRange ss:Name="' & $Name & '" ss:RefersTo="=' & $location & '"/>') ; Ex: <NamedRange ss:Name="qty" ss:RefersTo="='Page 1'!R2C1"/> ; Ex: <NamedRange ss:Name="value" ss:RefersTo="='Page 1'!R2C2"/> EndFunc ; -------------------------------------------------------------------------------------------------- ; Close Worksheet named range section ; -------------------------------------------------------------------------------------------------- Func _XLSCloseWSNames($file) FileWriteLine($file, ' </Names>') EndFunc ; -------------------------------------------------------------------------------------------------- ; Begin WorkSheet definition ; -------------------------------------------------------------------------------------------------- Func _XLSStartWSDefinition($file) FileWriteLine($file, ' <Table x:FullColumns="1" x:FullRows="1">') EndFunc ; -------------------------------------------------------------------------------------------------- ; Define column size ; -------------------------------------------------------------------------------------------------- Func _XLSColumnSize($file, $col, $size) FileWriteLine($file, ' <Column ss:Index="'&$col&'" ss:AutoFitWidth="0" ss:Width="'&$size&'"/>') EndFunc ; -------------------------------------------------------------------------------------------------- ; Add a new row in current worksheet ; -------------------------------------------------------------------------------------------------- Func _XLSAddRowInWorkSheet($file, $height=-1) If $height = -1 Then FileWriteLine($file, ' <Row ss:AutoFitHeight="1">') Else FileWriteLine($file, ' <Row ss:AutoFitHeight="0" ss:Height="'& $height &'">') EndIf EndFunc ; -------------------------------------------------------------------------------------------------- ; Add a cell (column) in the cirrent row of the current worksheet ; -------------------------------------------------------------------------------------------------- Func _XLSAddCellInRow($file, $data, $formula="", $type=$XMLXLS_STRING, $style="Default") Local $Cell =' <Cell ' If $formula <> "" Then $Cell &= 'ss:Formula="=' & $formula & '" ' ; formulae example: RC[-1]*2 or R1C1*2 ; formulae example: Sheet2!R[1]C*2 FileWriteLine($file, $Cell & 'ss:StyleID="' & $style & '"><Data ss:Type="' & $type & '">' & $data & '</Data></Cell>') EndFunc ; -------------------------------------------------------------------------------------------------- ; Close current row definition ; -------------------------------------------------------------------------------------------------- Func _XLSCloseRow($file) FileWriteLine($file, ' </Row>') EndFunc ; -------------------------------------------------------------------------------------------------- ; Close current worksheet definition ; -------------------------------------------------------------------------------------------------- Func _XLSCloseWorkSheet($file, $orientation=$XMLXLS_PORTRAIT, $mbottom = 0.98, $mleft=0.78, $mright=0.78, $mtop=0.98, $hmargin=0.5, $fmargin=0.5) FileWriteLine($file, ' </Table>') FileWriteLine($file, ' <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">') FileWriteLine($file, ' <PageSetup>') FileWriteLine($file, ' <Layout x:Orientation="'&$orientation&'"/>') FileWriteLine($file, ' <Header x:Margin="'&$hmargin&'"/>') FileWriteLine($file, ' <Footer x:Margin="'&$fmargin&'"/>') FileWriteLine($file, ' <PageMargins x:Bottom="'&$mbottom&'" x:Left="'&$mleft&'" x:Right="'&$mright&'" x:Top="'&$mtop&'"/>') FileWriteLine($file, ' </PageSetup>') FileWriteLine($file, ' </WorksheetOptions>') FileWriteLine($file, ' <ss:ActiveSheet>Page 2</ss:ActiveSheet>') FileWriteLine($file, ' </Worksheet>') EndFunc ; -------------------------------------------------------------------------------------------------- ; Close Excel workbook, the file now is readable by excel ; -------------------------------------------------------------------------------------------------- Func _XLSCloseWorkBook($file) FileWriteLine($file, '</Workbook>') If Not IsString($file) Then FileClose($file) EndFunc ; ------------------------------------------------------------------------------- ; Create a relative (to $l,$c) formulae to access to $l2,$c2 in sheet $sheet ; ------------------------------------------------------------------------------- Func _XLSlc2rc($l1, $c1, $l2, $C2, $sheet) Local $dc, $dl, $f $dc = $c2-$c1 $dl = $l2-$l1 $f="R" if $sheet <> "" Then $f = $sheet & "!" & $f if $dl<>0 Then $f &= '[' & $dl & ']' $f &= "C" if $dc<>0 Then $f &= '[' & $dc & ']' Return $f EndFunc
  3. Updated version: #include <GuiConstants.au3> #Include <GuiEdit.au3> ;------------------------------------------------------------------------------------------------------ ;- C O N S O L E D E M O ;------------------------------------------------------------------------------------------------------ #comments-start Func ConsoleWinDemo() Global $ConsoleID=0 Dim $Tab[8]=["|", "/", "--", "\", "|", "/", "--", "\"] $ConsoleID = ConsoleWinCreate(-1, -1, 638, 326, "Console Demo...", "Starting demo...", True) ConsoleWinWrite($ConsoleID, "Example: writting to the console a line") ConsoleWinWrite($ConsoleID, "Example: writting a string without line feed") For $i=0 To 7 ConsoleWinWrite($ConsoleID, ".", $i*5, True) Sleep(500) Next ConsoleWinWrite($ConsoleID, "") ConsoleWinWrite($ConsoleID, "Example: rewritting the last string") For $i=0 To 7 ConsoleWinWrite($ConsoleID, $Tab[$i], 50+$i*5, True, True) Sleep(500) Next ConsoleWinWrite($ConsoleID, "") ConsoleWinWrite($ConsoleID, "Example: input from console.") $answer = ConsoleWinInput($ConsoleID, "What is your age?") ConsoleWinWrite($ConsoleID, "You have answered: " & $answer) ConsoleWinWrite($ConsoleID, "Example: input from console on another line. What is your age?") $answer = ConsoleWinInput($ConsoleID, "") ConsoleWinWrite($ConsoleID, "You have answered: " & $answer) ConsoleWinWrite($ConsoleID, "Example: Clearing console in five seconds...") Sleep(5000) ConsoleWinClear($ConsoleID) ConsoleWinWrite($ConsoleID, "Demo finished! Exiting in five seconds...") Sleep(5000) Exit EndFunc #comments-end ;------------------------------------------------------------------------------------------------------ ;- C O N S O L E L I B R A R Y ;------------------------------------------------------------------------------------------------------ ;=============================================================================== ; Description: Create a Window console to display status text information with history ; Parameter(s): $x - x position of the window ; $y - y position of the window ; $width - Optional - Window width ; $height - Optional - Window height ; $Title - Optional - Console Window title ; $text - Optional - Initial text to display. ; $CreateProgress - Optional - Create Progress (True/False) ; $BgColor - Optional - background color ; $FgColor - Optional - Foreground color ; $Transparency - Optional - Transparency (0=Invisible, 255=Visible) ; $LogFile - Optional - File to log all console text ; Requirement(s): None ; Return Value(s): The Console ID ; Author(s): Jerome DERN (jerome "at" dern "dot" fr) ; Note(s): None ;=============================================================================== Func ConsoleWinCreate($x, $y, $width=638, $height=126, $Title="Console", $Text="", $CreateProgress=False, $BgColor=0xFFFFFF, $FgColor=0xFF0000, $Transparency=255, $LogFile="") Dim $Console[4] If $Text <> "" Then $Text=$Text & @CRLF $Console[0] = GuiCreate($Title, $width, $height, $x, $y, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) GUISetOnEvent($GUI_EVENT_CLOSE, "ConsoleWinExitEvent") If $CreateProgress Then $height -= 20 $Console[1] = GuiCtrlCreateEdit($Text, 0, 0, $width-1, $height-1, BitOR($ES_MULTILINE, $ES_READONLY, $ES_AUTOVSCROLL,$WS_HSCROLL,$WS_VSCROLL)) GUICtrlSetBkColor($Console[1], $BgColor) GUICtrlSetColor($Console[1], $FgColor) GUICtrlSetResizing($Console[1], $GUI_DOCKBORDERS) GUICtrlSetFont($Console[1], 9, 400, 0, "Courrier New") GUICtrlSetLimit($Console[1], 500000) $Console[2] =0 If $CreateProgress Then $Console[2] = GUICtrlCreateProgress(0, $height+5, $width-1, 12) if $Transparency<255 Then WinSetTrans($Console[0], "", $Transparency) DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $Console[0], "int", 300, "long", 0x00080000) GuiSetState(@SW_SHOW, $Console[0]) $Console[3] = $LogFile Sleep(50) Return $Console EndFunc ;=============================================================================== ; Description: Create a Widget console to display status text information with history ; Parameter(s): $gui - Gui window to include widget ; $x - x position of the Widget ; $y - y position of the Widget ; $width - Optional - Widget width ; $height - Optional - Widget height ; $Title - Optional - Console Window title ; $text - Optional - Initial text to display. ; $CreateProgress - Optional - Create Progress (True/False) ; $BgColor - Optional - background color ; $FgColor - Optional - Foreground color ; $LogFile - Optional - File to log all console text ; Requirement(s): None ; Return Value(s): The Console ID ; Author(s): Jerome DERN (jerome "at" dern "dot" fr) ; Note(s): None ;=============================================================================== Func ConsoleCreate($gui, $x, $y, $width=638, $height=126, $Text="", $CreateProgress=False, $BgColor=0xFFFFFF, $FgColor=0xFF0000, $LogFile="") Dim $Console[4] If $Text <> "" Then $Text=$Text & @CRLF $Console[0] = $gui If $CreateProgress Then $height -= 20 $Console[1] = GuiCtrlCreateEdit($Text, $x, $y, $width-1, $height-1, BitOR($ES_MULTILINE, $ES_READONLY, $ES_AUTOVSCROLL,$WS_HSCROLL,$WS_VSCROLL)) GUICtrlSetBkColor($Console[1], $BgColor) GUICtrlSetColor($Console[1], $FgColor) GUICtrlSetResizing($Console[1], $GUI_DOCKBORDERS) GUICtrlSetFont($Console[1], 10, 400, 0, "Courrier New") GUICtrlSetLimit($Console[1], 500000) $Console[2] =0 If $CreateProgress Then $Console[2] = GUICtrlCreateProgress($x, $y+$height+5, $width-1, 12) $Console[3] = $LogFile Return $Console EndFunc Func ConsoleWinExitEvent() GUIDelete(@GUI_WinHandle) EndFunc ;=============================================================================== ; Description: Close the Console ; Parameter(s): $ConsoleID - The console ID ; Requirement(s): None ; Return Value(s): None ; Author(s): Jerome DERN (jerome "at" dern "dot" fr) ; Note(s): None ;=============================================================================== Func ConsoleWinClose($ConsoleID) If Not IsArray($ConsoleID) Then Return GUIDelete($ConsoleID[0]) DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $ConsoleID[0], "int", 400, "long", 0x00090000) $ConsoleID[0] = 0 $ConsoleID[1] = 0 $ConsoleID[2] = 0 EndFunc ;=============================================================================== ; Description: Change the title of Console ; Parameter(s): $ConsoleID - The console ID ; $Title - The new title ; Requirement(s): None ; Return Value(s): None ; Author(s): Jerome DERN (jerome "at" dern "dot" fr) ; Note(s): None ;=============================================================================== Func ConsoleWinChangeTitle($ConsoleID, $Title) If Not IsArray($ConsoleID) Then Return WinSetTitle($ConsoleID[0], "", $Title) EndFunc ;=============================================================================== ; Description: Write a message to the console ; Parameter(s): $ConsoleID - Console ID returned by ConsoleWinCreate ; $text - Text to display. ; $Progress - Optional - Progress value (0-100) ; $NoCRLF - Optional - Don't add CRLF and the end of text ; $Replace - Optional - Replace last line ; Requirement(s): ConsoleWinCreate called first ; Return Value(s): None ; Author(s): Jerome DERN (jerome "at" dern "dot" fr) ; Note(s): None ;=============================================================================== Func ConsoleWinWrite($ConsoleID, $Text, $Progress=-1, $NoCRLF=False, $Replace=False) Local $string, $pos, $end If Not IsArray($ConsoleID) Then Return If $Replace Then $string = GUICtrlRead($ConsoleID[1]) $pos = StringInStr($string, @CRLF, 0, -1) If $pos > 0 Then $pos += 1 $end = StringLen($string) _GUICtrlEdit_SetSel($ConsoleID[1], $pos, $end) Else $pos = StringLen(GUICtrlRead($ConsoleID[1])) _GUICtrlEdit_SetSel($ConsoleID[1], $pos, $pos) EndIf If StringLen(GUICtrlRead($ConsoleID[1]))>499000 Then $string = StringRight(GUICtrlRead($ConsoleID[1]), 499000) GUICtrlSetData ($ConsoleID[1], $string) EndIf If $NoCRLF = False Then $Text = $Text & @CRLF GUICtrlSetData ($ConsoleID[1], $Text, 1) If $ConsoleID[2] >0 And $Progress>=0 Then GUICtrlSetData($ConsoleID[2], $Progress) If $ConsoleID[3] <> "" Then FileWrite($ConsoleID[3], $Text) Return $ConsoleID EndFunc ;=============================================================================== ; Description: Ask for the user to input something ; Parameter(s): $ConsoleID - Console ID returned by ConsoleWinCreate ; $text - Text to display, the question. ; $Progress - Optional - Progress value (0-100) ; Requirement(s): ConsoleWinCreate called first ; Return Value(s): What user have typed. ; Author(s): Jerome DERN (jerome "at" dern "dot" fr) ; Note(s): $text could be an empty string ;=============================================================================== Func ConsoleWinInput($ConsoleID, $Text, $Progress=-1) Local $string, $pos, $str If Not IsArray($ConsoleID) Then $string = InputBox("Question", $Text) Else WinSetOnTop($ConsoleID[0], "", 1) WinFlash($ConsoleID[0], "", 5, 100) WinActivate($ConsoleID[0]) $string = GUICtrlRead($ConsoleID[1]) $pos = StringLen($string) _GUICtrlEdit_SetSel($ConsoleID[1], $pos, $pos) GUICtrlSetData ($ConsoleID[1], $Text, 1) GUICtrlSetStyle($ConsoleID[1], BitOR($ES_MULTILINE, $ES_AUTOVSCROLL, $WS_HSCROLL, $WS_VSCROLL, $ES_WANTRETURN)) GUICtrlSetState($ConsoleID[1], $GUI_FOCUS) If $Text <> "" Then ; Wait for the user to input something While 1 Sleep(100) $String=GUICtrlRead($ConsoleID[1]) If StringRight($string, 2) = @CRLF Then ExitLoop ; Ensure that everything is typed at the end of edit control $pos = StringLen($String) _GUICtrlEdit_SetSel($ConsoleID[1], $pos, $pos) WEnd $pos = StringInStr($string, $Text, 0, -1) If $pos >0 Then $pos += StringLen($Text) Else $str = $string ; Wait for the user to input something While 1 Sleep(100) $String=GUICtrlRead($ConsoleID[1]) If StringRight($string, 2) = @CRLF And $string <> $str Then ExitLoop ; Ensure that everything is typed at the end of edit control $pos = StringLen($String) _GUICtrlEdit_SetSel($ConsoleID[1], $pos, $pos) WEnd $pos = StringInStr(StringLeft($string, StringLen($string)-2), @CRLF, 0, -1) If $pos > 0 Then $pos += 1 EndIf $string = StringMid($string, $pos) $string = StringLeft($string, StringLen($string)-2) GUICtrlSetStyle($ConsoleID[1], BitOR($ES_MULTILINE, $ES_READONLY, $ES_AUTOVSCROLL,$WS_HSCROLL,$WS_VSCROLL)) If $ConsoleID[2] >0 And $Progress>=0 Then GUICtrlSetData($ConsoleID[2], $Progress) WinSetOnTop($ConsoleID[0], "", 0) EndIf Return $string EndFunc ;=============================================================================== ; Description: Set progress value of the console ; Parameter(s): $ConsoleID - The console ID ; $Value - The new value to set ; $min - Optional - The minimum value possible ; $max - Optional - The maximum value possible ; Requirement(s): None ; Return Value(s): None ; Author(s): Jerome DERN (jerome "at" dern "dot" fr) ; Note(s): None ;=============================================================================== Func ConsoleSetProgress($ConsoleID, $value, $min=0, $max=100) Local $percent If Not IsArray($ConsoleID) Then Return $percent = ($value-$min)*100 If $percent <0 Then $percent = 0 $percent /= ($max-$min) If $ConsoleID[2] >0 Then GUICtrlSetData($ConsoleID[2], $percent) EndFunc ;=============================================================================== ; Description: Clear the console ; Parameter(s): $ConsoleID - The console ID ; Requirement(s): None ; Return Value(s): None ; Author(s): Jerome DERN (jerome "at" dern "dot" fr) ; Note(s): None ;=============================================================================== Func ConsoleWinClear($ConsoleID) If Not IsArray($ConsoleID) Then Return GUICtrlSetData ($ConsoleID[1], "") If $ConsoleID[2] >0 Then GUICtrlSetData($ConsoleID[2], 0) If $ConsoleID[3] <> "" Then FileDelete($ConsoleID[3]) EndFunc ;=============================================================================== ; Description: Flash the console ; Parameter(s): $ConsoleID - The console ID ; Requirement(s): None ; Return Value(s): None ; Author(s): Jerome DERN (jerome "at" dern "dot" fr) ; Note(s): None ;=============================================================================== Func ConsoleFlash($ConsoleID) If Not IsArray($ConsoleID) Then Return WinFlash($ConsoleID[0], "", 5, 100) EndFunc ;=============================================================================== ; Description: Save the content of the console to a file ; Parameter(s): $ConsoleID - The console ID ; $FileName - The filename used to save ; Requirement(s): None ; Return Value(s): Write status, same as FileWrite ; Author(s): Jerome DERN (jerome "at" dern "dot" fr) ; Note(s): None ;=============================================================================== Func ConsoleWinSave($ConsoleID, $FileName) Local $string If Not IsArray($ConsoleID) Then Return $string = GUICtrlRead($ConsoleID[1]) Return FileWrite($FileName, $string) EndFunc <script src="http://shots.snap.com//client/inject.js?site_name=0" type="text/javascript">
  4. To have a GUI control (ActiveX) displaying a powerpoint is a nice way to enhance Autoit GUI. It can be used to do an interractive training... It is basically the same interrest than an Excel Control in an AutoIt window. So any other people have solution to do that? (Showing presentation in a separate window or in full Screen doesn't correspond to what I need... Thanks in advance
  5. Hi, I want to display a powerpoint file in an area of an Autoit window, is it possible? ActiveX? An example? Thanks for any help JD
  6. Yes Windows allows that, you can even drag an URL from IEXPLORER address bar to another application but this kind of things are automatically refused by autoit applications even if drag & drop is activated on window... Please help, really need it... Anyone? Thanks JD
  7. Updated June 13th, new functions and bug corrected. See first post of this topic for listing.
  8. Hi, Here are a source code to fit any string text into a fixed size label. String too long are shortened automatically by using "..." in the middle of the string. Func AdaptStringToSize($string, $font, $size, $width) $len = StringLen($string) $gui = GuiCreate("", $width+1, 1,-1, -1) GUISetFont($size, 400, 0, $font) $str = $string Do $label = GuiCtrlCreateLabel($str, 0, 0) $pos = ControlGetPos($gui, $str, $label) If $pos[2] > $width Then $sub = Int(($width-$pos[2])/$size)-1 If $sub <=0 then $sub = 1 $len -= $sub $str = LimitStringSize($string, $len) EndIf Until $pos[2] <= $width GUIDelete($gui) GUISetFont($size, 400, 0, $font) Return $str EndFunc
  9. Hi, I want to be able to drag some text from any other/external application to a gui/program made in autoit. I found a solution with drag & drop of files but it doesn't work with text (drop refused by gui)... Is there a solution for that? Thanks for any help JD
  10. Hi, This example seems partially inspired from my TimerLib (same name, same function names, etc...) but this one doesn't works because this is more complicated than it seems. Please avoid sucking up other people's scripts with no added value (subtracted value I should say)... Thanks in advance Jérôme
  11. The is no way except finding a string which is the minimum string to catch all search need, in your case: food will catch "food" and also "foods" Thanks JD
  12. Hi, I read all these comments and interrest it's nice ! Thanks for those that have worked on it to add functions ! Any other idea? Thanks JD
  13. Thanks all for your positive comments... I was built for a personnal project in 5 hours.
  14. Hi, Thanks a lot, indeed I created it for a special personnal need before SQLite were available and it works pretty well without any bugs yet. It is based on an open source low level library that have been deeply reworked in order to acheive the level of functonnality I wanted. I can release the sources (C language) if you want, but in this case release here the modifications. But no it is not in my plans to spend more work on this subject. Sorry. Let me know. JD
×
×
  • Create New...