-
Posts
261 -
Joined
-
Last visited
Reputation Activity
-
Wombat reacted to martin in Add button to third party gui?
It is actually quite easy to do. Create a popup window which is big enough to hold the button. Make the window positionthe same as the position you want it to be in the 3rd party window. Set the parent for the popup to be the 3rd party window and it will move there. You can react to the button press in your script as normal. Here is a simple example.
;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=Pumac.exe #AutoIt3Wrapper_res_requestedExecutionLevel=asInvoker #EndRegion;**** Directives created by AutoIt3Wrapper_GUI **** ; *** Start added by AutoIt3Wrapper *** #include <WindowsConstants.au3> ; *** End added by AutoIt3Wrapper *** AutoItSetOption('trayiconhide', 1) Run('calc.exe');just to have a window to use $ParentTitle = "Calculator"; While Not WinExists($ParentTitle) Sleep(200) WEnd ConsoleWrite("ss" & @CRLF) $hParentWindow = WinGetHandle($ParentTitle) ;guess and experiment $fleft = 12 $ftop = 38 $winf7 = GUICreate("F7",30, 30, $fleft, $ftop, $WS_POPUP) GUISetBkColor(0xff0000) $Btnf7 = GUICtrlCreateButton("F7", 1, 1, 28, 28) ;GUICtrlSetFont(-1, 16) DllCall("user32.dll", "int", "SetParent", "hwnd", $winf7, "hwnd", $hParentWindow) GUISetState() While WinExists($hParentWindow) if GUIGetMsg() = $Btnf7 then msgbox(262144,'Click', 'F7 pressed') WEnd WinKill($winf7) For a UDF which does this for you search for anygui.
-
Wombat reacted to jaberwacky in MouseHoverCallTips [11/24/2023]
When ever you hover your mouse over a native function, user defined function, or an AutoItObject method then you will see the calltip for that function.
Click "Like This" if you found this useful!
To use this just place the following lua file in the "...AutoIt3\SciTE\lua" directory.
MouseHoverCallTips.zip
downloads:741
After you have done that then open SciTE and click 'Options' --> 'Open Lua Startup Script' and paste this line after the other lines (may require administrative rights):
LoadLuaFile("MouseHoverCallTips.lua") Updates and changes:
-
Wombat reacted to JohnOne in AudBox
Things like...
If $Aud=1 Then $auSOUND=@WindowsDir & "\Media\chimes.wav" If $Aud=2 Then $auSOUND=@WindowsDir & "\Media\Windows Error.wav" If $Aud=3 Then $auSOUND=@WindowsDir & "\Media\Windows Notify.wav" If $Aud=4 Then $auSOUND=@WindowsDir & "\Media\Windows Ding.wav" If $Aud=5 Then $auSOUND=@WindowsDir & "\Media\Windows User Account Control.wav" If $Aud=6 Then $auSOUND=@WindowsDir & "\Media\Windows Balloon.wav" If $Aud=7 Then $auSOUND=@WindowsDir & "\Media\Windows Default.wav" If $Aud=8 Then $auSOUND=@WindowsDir & "\Media\Windows Exclamation.wav" If $Aud=9 Then $auSOUND=@WindowsDir & "\Media\Windows Navigation Start.wav" You should use If,, elseIf
Or a switch case block, otherwise you are making a lot of comparisons that are not needed.
-
Wombat reacted to JLogan3o13 in SCCM UDF
I am finally back at a customer location where I could work with Microsoft System Center Configuration Manager, and wanted to update the script from >this thread. This time around, rather than a full GUI it is simply a UDF, allowing the user to employ the functions however they would like. This has been tested on 2012 and 2012 R2; unfortunately I no longer have any customers with access to 2007.
Currently there are 11 public functions; will continue to update and provide examples as I get a chance. There is also an _SCCM_Constants.au3 that needs to be copied to the Includes directory.
Updated 10/14/2014: Added _SCCM_DeletePC function and example
Updated 04/12/2015: Added _SCCM_RefreshCollection function and example
_SCCM.au3
_SCCM_Constants.au3
Examples:
-
Wombat reacted to UEZ in A bug I cannot figure out, any idea?
While your About function is running the code is caught in the while / wend loop:
While WinExists("About Xex Launcher", "")=1 Switch GUIGetMsg() Case $AbtBtn_close GUIDelete($AboutGUI) EndSwitch WEnd How should your main gui work?
What you can try is to use GUISetOnEvent on main GUI but I'm not sure whether it will work when About function is called. Test it.
Regarding the "bug" - I wouldn't say it is a bug rather it is the behavior how the GUI reacts when you initialize the child GUI that way.
Br,
UEZ
-
Wombat reacted to JScript in DVI-Remote (Remote Desktop entirely in AutoIt) - OpenSource!
Hello everyone!
I know there are many programs (including freeware) for this purpose, but the best ones are paid (very expensive), only give you 5 minutes section...
I thought about: Why not in AutoIt? So I did!
Is not full, there is still a few things to be done, but it is quite functional!
What already does:
1 - Remote Viewing (of course)
2 - Control by mouse, clicks, 2 clicks, scrolling (MouseWheel)
3 - Control by keyboard, now is complete!
4 - Supports all languages, currently English and Portuguese
5 - ChatBox conversation
6 - Save the current image into file
7 - Two types of compression: LZMA (level 2) and LZNT native
8 - Show remote cursor (Yes, you can use!)
9 - Capture only the window that is active (very fast, recommended!)
What left to do:
1 - Save the section on avi movie (in progress)
2 - Send and receive files in a simple gui
3 - Drag & Drop files and folders to remote computer (in progress)
4 - Need more?
Here are some sample images:
Update (02/10/2011 - 11:57)
Download:
DVI-Remote_(RedirectLink).html
2.09k (Previous downloads: 817)
I have tested on:
Product: VMware® Workstation
Version: 7.1.0 build-261024
Network Adapter: Bridged (Connected directly to the physical network)
and: Two real PCs (in different networks)
Credits:
ProgAndy: Keyboard and Mouse functions.
Yashied: WinAPIEx.au3, NotifyBox.au3
trancexx: _LZNTCompress.au3
Ward: LZMA Compression Machine Code UDF
Free Software
João Carlos.
-
Wombat got a reaction from dilipped in Newbie Question
I began by looking for tutorials and whatnot, but alas the best thing to do is learn how to use google + this forum and just search for what it is you are wanting to do. 9 times out of 10 it's been done before (maybe differently than you are approaching it) and all you need to do is ask the right question to get the right answer. Coding and life in general can be surmised by this statement:
You get out of it what you put in to it. So if you're not getting what you want out of it you are not inputting the required content. Computers are at this time re-active, they do what you tell them to or what others have told them to do. So if you are having trouble finding what you're looking for on the forum, maybe change how you are looking for it. Also, remember search engines run on databases and are best utilized with keywords not entire sentences. You limit your results when using complete sentences.
If you are looking for examples check here and look through and see how they are doing theirs: http://www.autoitscript.com/forum/forum/9-example-scripts/
If you want to get an idea of how you can start, 1 way at least, then open SciTE and go to Tools>Koda(form designer) and play around with it, once you have a gui you like press generate form code and look at how the code behind the form you just made is laid out. This is how I got started.
good luck
-
Wombat reacted to JohnOne in Capture OnEntry event, Help?
In fact there is a big UIAutomation UDF project in example scripts which might be greatly useful to you.
It can access all kinds of window controls which general win32 programming cannot.
Worth a look like.
Sticky at the top.
-
Wombat reacted to Melba23 in Setting controls placement via resolution...
Wombat,
Look at GUICtrlSetResizing or the Opt equivalent - this allows the GUI to be set to whatever size you require and the controls alter size automatically. Here is an example I posted a while ago which also maintains the same aspect ratio:
#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ; Set resize mode for controls Opt("GUIResizeMode", $GUI_DOCKAUTO) $hGUI = GUICreate("Test", 500, 300, -1, -1, BitOR($WS_SIZEBOX, $WS_SYSMENU)) $cButton_1 = GUICtrlCreateButton("Test 1", 10, 10, 80, 30) $cButton_2 = GUICtrlCreateButton("Test 2", 10, 50, 80, 30) GUISetState() GUIRegisterMsg($WM_SIZING, "_WM_SIZING") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _WM_SIZING($hWnd, $iMsg, $wParam, $lParam) #forceref $iMsg, $wParam, $wParam If $hWnd = $hGUI Then Local $iNew_H, $iNew_W Local $sRect = DllStructCreate("Int[4]", $lParam) Local $iLeft = DllStructGetData($sRect, 1, 1) Local $iTop = DllStructGetData($sRect, 1, 2) Local $iRight = DllStructGetData($sRect, 1, 3) Local $iBottom = DllStructGetData($sRect, 1, 4) ; Keep the same aspect ratio Switch $wParam ; drag side or corner Case 1, 2 ; $WMSZ_LEFT, $WMSZ_RIGHT $iNew_H = Int(($iRight - $iLeft) * 300 / 500) DllStructSetData($sRect, 1, DllStructGetData($sRect, 1, 2) + $iNew_H, 4) Case Else $iNew_W = Int(($iBottom - $iTop) * 500 / 300) DllStructSetData($sRect, 1, DllStructGetData($sRect, 1, 1) + $iNew_W, 3) EndSwitch EndIf EndFunc You can even get the font to adjust size as well by using a message handler - but you will have to wait until tomorrow if you want an example of that as I will have to strip it out of another script.
M23
-
Wombat reacted to UEZ in Drawing on a ScreenCapture
I think without using GDI/GDI+ it is not possible to modify the taken screenshot.
I cannot remember whether this version already supports multi monitors but you can give a try ->
Otherwise AutoIt Windows Screenshooter supports multiple monitors.
Br,
UEZ
-
Wombat reacted to minxomat in Solve any equation with this 175 Byte function
Only possibility to optimize this further is to reduce the step depth (999 in the 175B version). In the most cases, 9 steps are sufficient for a 4bit comma precision, so that would be 173 Bytes
-
Wombat reacted to JLogan3o13 in A comparison of methods...
I tend to favor a mix of approaches, just because I have seen the volume of crap that can be left behind in the registry should the person have had MS Office at one time and then uninstalled. You might combine a look in the registry's Uninstall key, a look under the Explorer key for a specific extension to see what it is set to open with (is .doc set to open with MSWord or the LibreOffice equiv. for example), and then I might do something like this to grab from WMI. You could easily change the msgbox into an "If MS Office Then..." statement:
$WMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & @ComputerName & "\root\cimv2") $aItems = $WMI.ExecQuery("SELECT * FROM Win32_Product") For $element In $aItems MsgBox(0, "", $element.Name) Next -
Wombat reacted to jdelaney in A comparison of methods...
Did you know you can create excel spread sheets without excel installed? You won't be able to view them, but just throwing that out there. I have a sample in my sig, and pleanty more are out there.
So if you farm out work, as long as the end results of the logging are on a station with excel, there is no need to differentiate with what app to create the logging.
-
Wombat reacted to UEZ in Fade in label text
Then try this here:
#AutoIt3Wrapper_Version=beta ;should be at least AutoIt version 3.3.9.21+ #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WinAPITheme.au3> Const $STM_SETIMAGE = 0x0172 _GDIPlus_Startup() $hGUI = GUICreate("Test", 468, 324) $iLabel = GUICtrlCreatePic("c:\Program Files (x86)\AutoIt3\Examples\GUI\msoobe.jpg", 0, 0, 468, 323) GUICtrlSetState(-1, $GUI_DISABLE) $iButton = GUICtrlCreateButton("Button", 17, 23, 70, 67) $iInput = GUICtrlCreateInput("Input", 109, 28, 338, 62) $iRadio = GUICtrlCreateRadio("Radio", 17, 114, 78, 18) _WinAPI_SetWindowTheme(GUICtrlGetHandle($iRadio), "", "") GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetColor(-1, 0xFFFFFF) $iRadio2 = GUICtrlCreateRadio("Radio", 17, 140, 55, 19) _WinAPI_SetWindowTheme(GUICtrlGetHandle($iRadio2), "", "") GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetColor(-1, 0xFFFFFF) $iCheckbox = GUICtrlCreateCheckbox("Checkbox", 109, 114, 83, 18) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetColor(-1, 0xFFFFFF) _WinAPI_SetWindowTheme(GUICtrlGetHandle($iCheckbox), "", "") $iProgress = GUICtrlCreateProgress(109, 140, 338, 29) GUICtrlSetData(-1, 50) $iLabel_Pseudo = GUICtrlCreatePic("", 17, 184, 430, 88) $iButton2 = GUICtrlCreateButton("Exit", 391, 284, 56, 29) GUISetState() AdlibRegister("LabelFader", 13) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $iButton2 AdlibUnRegister("LabelFader") _GDIPlus_Shutdown() Exit EndSwitch WEnd Func LabelFader() Local Static $iColor = 0x00, $iDir = 2, $c = 0 Local $aText[2] = ["AutoIt rulez!", "coded by UEZ"] Local $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000 + $iColor * 0x10000 + $iColor * 0x100 + $iColor) Local $hBitmap = _GDIPlus_BitmapCreateFromScan0(430, 88) Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsSetTextRenderingHint($hCtxt, $GDIP_TEXTRENDERINGHINT_ANTIALIASGRIDFIT) _GDIPlus_GraphicsClear($hCtxt, 0xFFFFFFFF) Local $hFormat = _GDIPlus_StringFormatCreate() Local $hFamily = _GDIPlus_FontFamilyCreate("Comic Sans MS") Local $hFont = _GDIPlus_FontCreate($hFamily, 45) Local $tLayout = _GDIPlus_RectFCreate(0, 0, 430, 88) _GDIPlus_StringFormatSetAlign($hFormat, 1) $iColor += $iDir If $iColor > 0xFD Then $c += 1 $iDir *= -1 ElseIf $iColor < 0x02 Then $iDir *= -1 EndIf _GDIPlus_GraphicsDrawStringEx($hCtxt, $aText[Mod($c, 2)], $hFont, $tLayout, $hFormat, $hBrush) _GDIPlus_BrushDispose($hBrush) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_GraphicsDispose($hCtxt) Local $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _GDIPlus_BitmapDispose($hBitmap) _WinAPI_DeleteObject(GUICtrlSendMsg($iLabel_Pseudo, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap)) _WinAPI_DeleteObject($hHBitmap) EndFunc ;==>LabelFader
AutoIt version 3.3.9.21+ is required
Br,
UEZ
-
Wombat reacted to Yashied in Animate UDF
LAST VERSION - 1.2
27-Dec-11
This UDF helps you to create animated icon in the system tray (only one icon can be used). Very easy to use! I hope that it will be useful for someone. To work properly the example which is shown below, you need to download an archive containing the necessary icons. Any feedback and suggestions please.
Available functions
Animate UDF Library v1.2
Previous downloads: 1112
Animate.zip
Example
#Include <GUIConstantsEx.au3> #Include <SliderConstants.au3> #Include <StaticConstants.au3> #Include <WindowsConstants.au3> #Include "Animate.au3" Opt('MustDeclareVars', 1) Opt('TrayAutoPause', 0) Global $Button, $Slider, $Msg _Animate_LoadFromFile(@ScriptDir & '\Flag.png') ;~For $i = 1 To 12 ;~ _Animate_AddIcon(@ScriptDir & '\Flag\' & $i & '.ico', 0) ;~Next _Animate_SetDelay(50) _Animate_ShowIcon() GUICreate('Animation Test', 400, 110) GUICtrlCreateLabel('Fast', 10, 30, 28, 14, $SS_RIGHT) GUICtrlCreateLabel('Slow', 355, 30, 28, 14) $Slider = GUICtrlCreateSlider(42, 25, 310, 26, BitOR($TBS_AUTOTICKS, $WS_TABSTOP)) GUICtrlSendMsg(-1, $TBM_SETTICFREQ, 10, 0) GUICtrlSetLimit(-1, 250, 10) GUICtrlSetData(-1, 50) $Button = GUICtrlCreateButton('Start', 160, 75, 80, 25) GUICtrlSetState(-1, BitOR($GUI_DEFBUTTON, $GUI_FOCUS)) GUISetState() While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE ExitLoop Case $Slider _Animate_SetDelay(GUICtrlRead($Slider)) Case $Button If _Animate_IsAnimate() Then GUICtrlSetData($Button, 'Start') _Animate_Stop() Else GUICtrlSetData($Button, 'Stop') _Animate_Start() EndIf EndSwitch WEnd -
Wombat reacted to kylomas in 16 Buttons - what is the best way to code?
swstrau118,
Here's one way...
#include <ButtonConstants.au3> #include <Constants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <GuiButton.au3> #include <array.au3> #AutoIt3Wrapper_Add_Constants=n local $gui010 = guicreate('') local $aSize = wingetclientsize($gui010) local $lbl010 = guictrlcreatelabel('Some meaningful text',0,20,$aSize[0],20,bitor($ss_sunken, $SS_CENTER)) local $aButtons[16], $idx = 0 for $1 = 1 to 4 for $2 = 1 to 4 $aButtons[$idx] = guictrlcreatebutton('#' & $idx+1,$2*55,$1*55,35,35) $idx += 1 Next next guisetstate() while 1 switch guigetmsg() case $gui_event_close Exit case $aButtons[0] to $aButtons[ubound($aButtons)-1] for $1 = 0 to ubound($aButtons) - 1 if bitand(_GUICtrlButton_GetState($aButtons[$1]),$BST_FOCUS) = $BST_FOCUS then _Button_action($1+1) next EndSwitch WEnd func _Button_action($button_number) switch msgbox($MB_OKCANCEL,'','Button Pushed = ' & $button_number & @LF) case 1 ConsoleWrite('Doing something with button #' & $button_number & @LF) return case 2 ConsoleWrite('Returning without doing anything with button #' & $button_number & @LF) Return endswitch endfunc kylomas
edit: corrected return placement
-
Wombat reacted to FireFox in Adding picture as background to GUI
Hi,
Unfortunately I don't have this issue
It should be fixed by the repaint triggered on some WM (VSCROLL, HSCROLL, MOUSEWHEEL, KEYDOWN).
I suggest you to check if one of the above is not triggered or if there is a WM I forgot to add (make a ConsoleWrite of the $uMsg in the _MyEdit_Proc function).
Have you tried the richedit solution in the thread you linked?
Br, FireFox.
-
Wombat reacted to Wruck in Replacing the default web browser by your own script
There are a few links that give many of the registry keys you will need to either create or alter...
http://www.tomshardware.com/forum/170215-46-default-browser-registry
http://forums.techarena.in/technology-internet/1112113.htm
-
Wombat got a reaction from mLipok in Create Excel file through "Microsoft.XMLDOM"
this is just what i was asking Santa for christmas!! jk lol, But really this is absolutely AMAZING!.
-
Wombat reacted to mLipok in RDC Black Screen in AutoIT
Anyone can have a bad day, or a moment of doubt. I also happens So do not give up, raise your head and grow together with us. -
Wombat reacted to guinness in Avoid screensaver
I will play this game too...
Do MouseMove(Random(1, @DesktopWidth, 1), Random(1, @DesktopHeight, 1), 1) Until Sleep(30000) = 0 -
Wombat reacted to Melba23 in A little add-on(attaching a gui to another window)
Wombat,
Oops, forgot that bit!
How about this:
#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> If Not WinExists("Untitled - Notepad") Then Run("Notepad.exe") $hNotepad = WinWaitActive("Untitled - Notepad") Else $hNotepad = WinGetHandle("Untitled - Notepad") EndIf WinMove($hNotepad, "", 100, 100, 500, 500) Opt("GUIOnEventMode", 1) Opt("GUICloseOnEsc", 1) Global $fChild = False HotKeySet("q", "_SH_Child") Global $hGUI_Child _Create_Child() While 1 Sleep(10) If Not WinExists($hNotepad) Then Exit EndIf _Position_Child($hNotepad) WEnd Func _Create_Child() $hGUI_Child = GUICreate("Follower", 200, 500, -1, -1, BitOR($WS_POPUP, $WS_BORDER), 0, $hNotepad) GUISetBkColor(0xCCFFCC) _Position_Child($hNotepad) EndFunc ;==>_Create_Child Func _SH_Child() $fChild = Not $fChild If $fChild Then If Not $hGUI_Child Then _Create_Child() EndIf DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hGUI_Child, "int", 1000, "long", 0x00040001) ; $AW_SLIDE_IN_LEFT WinActivate($hNotepad) Else DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hGUI_Child, "int", 1000, "long", 0x00050002) ; $AW_SLIDE_OUT_LEFT EndIf EndFunc ;==>_SH_Child Func _Position_Child($hNotepad) Local $aGUI_Main_Pos = WinGetPos($hNotepad) WinMove($hGUI_Child, "", $aGUI_Main_Pos[0] + $aGUI_Main_Pos[2] + 2, $aGUI_Main_Pos[1]) EndFunc ;==>_Position_Child M23 -
Wombat reacted to Melba23 in A little add-on(attaching a gui to another window)
Wombat,
A "proof of concept" script that uses "q" as a HotKey for child activation:
#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> If Not WinExists("Untitled - Notepad") Then Run("Notepad.exe") $hNotepad = WinWaitActive("Untitled - Notepad") Else $hNotepad = WinGetHandle("Untitled - Notepad") EndIf WinMove($hNotepad, "", 100, 100, 500, 500) Opt("GUIOnEventMode", 1) Opt("GUICloseOnEsc", 1) Global $fChild = False HotKeySet("q", "_SH_Child") Global $hGUI_Child _Create_Child() GUIRegisterMsg($WM_MOVE, "_Position_Child") While 1 Sleep(10) If Not WinExists($hNotepad) Then Exit EndIf WEnd Func _Create_Child() $hGUI_Child = GUICreate("Follower", 200, 500, -1, -1, BitOR($WS_POPUP, $WS_BORDER), 0, $hNotepad) GUISetBkColor(0xCCFFCC) _Position_Child($hNotepad, 0, 0, 0) EndFunc ;==>_Create_Child Func _SH_Child() $fChild = Not $fChild If $fChild Then If Not $hGUI_Child Then _Create_Child() EndIf DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hGUI_Child, "int", 1000, "long", 0x00040001) ; $AW_SLIDE_IN_LEFT WinActivate($hNotepad) Else DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hGUI_Child, "int", 1000, "long", 0x00050002) ; $AW_SLIDE_OUT_LEFT EndIf EndFunc ;==>_SH_Child Func _Position_Child($hWnd, $iMsg, $wParam, $lParam) #forceref $iMsg, $wParam, $lParam If $hWnd <> $hNotepad Then Return Local $aGUI_Main_Pos = WinGetPos($hNotepad) WinMove($hGUI_Child, "", $aGUI_Main_Pos[0] + $aGUI_Main_Pos[2] + 2, $aGUI_Main_Pos[1]) EndFunc ;==>_Position_Child Let me know if you are interested and we can work on getting it as you want.
M23
-
Wombat reacted to jdelaney in Create Excel file through "Microsoft.XMLDOM"
I'm basing the basics (mostly just the XML structure) of this script off one of FireFox's: '?do=embed' frameborder='0' data-embedContent>>
I felt the need to make it more flexible, via the Microsoft.xmldom.
Using this object, not only can you create excel XML files, you can also update them. XPaths are used for everything, so it's easy to add additional rows/columns/sheets on the fly...I'll add another function to read in an already present file in a bit (just added in), but that function would be as simple as loading the contents into the object.
Multiple internal functions, but all you need are:
Func EXml_LoadFile($sCallersFile)
Func EXml_CreateFile()
Func EXml_AddCell($oCallersXML,$sCallersSheetName,$iCallersCellCol,$iCallersCellRow,$sCallersCellData)...this one creates the cell, or updates it if already present
Func EXml_SaveFile($oCallersXML,$sCallersFileName)
Example Usage
#include "EXml.au3" ; Set for overwrite of variable ;~ Global $gsEXml_DocProp_Author = "someAuthor" ;~ Global $gsEXml_DocProp_LastAuthor = "LastAuthorText" ;~ Global $gsEXml_DocProp_Created = "CreatedText" ;~ Global $gsEXml_DocProp_Company = "CompnayText" ;~ Global $gsEXml_DocProp_Version = "VersionText" $oXML = EXml_CreateFile() ; Can load, if the XML file is already present ;~ $oXML = EXml_LoadFile(@DesktopDir & "\test.xml") ; Add cell params: $oXMl, $sSheetName, $iColumn, $iRow, $sCellContents EXml_AddCell($oXML,"SheetName",5,10,"SomeValue1") EXml_AddCell($oXML,"SheetName",5,9,"SomeValue2") EXml_AddCell($oXML,"SheetNameTWO",1,2,"SomeValue3") EXml_AddCell($oXML,"SheetName",5,10,"SomeValueEDIT") EXml_AddCell($oXML,"SheetName",15,6,"SomeValue4") EXml_SaveFile($oXML,@DesktopDir & "\test.xml") Run(@ComSpec & " /c " & @DesktopDir & "\test.xml") ;~ ConsoleWrite(StringRegExpReplace($oXML.xml, "><",">" & @CRLF & "<") & @CRLF) Exit Notice, that you can add cells in at any order, you are not constrained to add everything in order.
Where EXml.au3 is:
#include-once #include <File.au3> Global $gsEXml_DocProp_Author = "AuthorText" Global $gsEXml_DocProp_LastAuthor = "LastAuthorText" Global $gsEXml_DocProp_Created = "CreatedText" Global $gsEXml_DocProp_Company = "CompnayText" Global $gsEXml_DocProp_Version = "VersionText" Func EXml_LoadFile($sCallersFile) Local $oXML = ObjCreate("Microsoft.XMLDOM") $oXML.Load($sCallersFile) Return $oXML EndFunc Func EXml_CreateFile() ;~ _FileCreate($sCallersFile) Local $oXML = ObjCreate("Microsoft.XMLDOM") $oXML.LoadXML('<?xml version="1.0"?><?mso-application progid="Excel.Sheet"?><Workbook />') Local $oWorkBook = $oXML.selectSingleNode("/Workbook") Local $oDocumentProperties = EXml_CreateFile_DocumentProperties($oXML,$oWorkBook) Local $oOfficeDocumentSettings = EXml_CreateFile_OfficeDocumentSettings($oXML,$oWorkBook) Local $oExcelWorkbook = EXml_CreateFile_ExcelWorkbook($oXML,$oWorkBook) Local $oStyles = EXml_CreateFile_Styles($oXML,$oWorkBook) With $oWorkBook .setAttribute("xmlns","urn:schemas-microsoft-com:office:spreadsheet") .setAttribute("xmlns:o","urn:schemas-microsoft-com:office:office") .setAttribute("xmlns:x","urn:schemas-microsoft-com:office:excel") .setAttribute("xmlns:ss","urn:schemas-microsoft-com:office:spreadsheet") .setAttribute("xmlns:html","http://www.w3.org/TR/REC-html40") .appendChild($oDocumentProperties) .appendChild($oOfficeDocumentSettings) .appendChild($oExcelWorkbook) .appendChild($oStyles) EndWith Return $oXML EndFunc Func EXml_AddCell($oCallersXML,$sCallersSheetName,$iCallersCellCol,$iCallersCellRow,$sCallersCellData) Local $oWorkBook = $oCallersXML.selectSingleNode("/Workbook") Local $oWorkSheet = $oCallersXML.selectSingleNode("//Worksheet[@ss:Name='" & $sCallersSheetName & "']") If Not IsObj($oWorkSheet) Then ; Create Worksheet, as needed $oWorkSheet = EXml_AddCell_CreateWorkSheet($oCallersXML,$sCallersSheetName) $oWorkBook.appendChild($oWorkSheet) EndIf Local $oTable = $oWorkSheet.selectSingleNode("./Table") Local $oRow = $oTable.selectSingleNode("./Row[@ss:Index='" & $iCallersCellRow & "']") If Not IsObj($oRow) Then ; Create Row, as needed $oRow = EXml_AddCell_CreateRow($oCallersXML,$oTable,$iCallersCellRow) $oRows = $oTable.selectNodes("./Row") If $oRows.length Then For $o In $oRows If Number($o.getAttribute("ss:Index")) > $iCallersCellRow Then $oTable.insertBefore($oRow,$o) ExitLoop EndIf Next Else $oTable.appendChild($oRow) EndIf EndIf Local $oCell = $oRow.selectSingleNode("./Cell[@ss:Index='" & $iCallersCellCol & "']") If Not IsObj($oCell) Then $oCell = EXml_AddCell_CreateCell($oCallersXML,$oTable,$iCallersCellCol,$sCallersCellData) $oCells = $oRow.selectNodes("./Cell") If $oCells.length Then For $o In $oCells If Number($o.getAttribute("ss:Index")) > $iCallersCellCol Then $oRow.insertBefore($oCell,$o) ExitLoop EndIf Next Else $oRow.appendChild($oCell) EndIf Else EXml_AddCell_UpdateCell($oCell,$sCallersCellData) EndIf Return $oCallersXML EndFunc Func EXml_SaveFile($oCallersXML,$sCallersFileName) $oCallersXML.save($sCallersFileName) EndFunc #region INTERNAL Func EXml_CreateFile_DocumentProperties($oCallersXML, $oCallersWorkbook) With $oCallersXML Local $oDocProps = .createElement("DocumentProperties") Local $oAuthor = .createElement("Author") Local $oLastAuthor = .createElement("LastAuthor") Local $oCreated = .createElement("Created") Local $oCompany = .createElement("Company") Local $oVersion = .createElement("Version") EndWith $oAuthor.text = $gsEXml_DocProp_Author $oLastAuthor.text = $gsEXml_DocProp_LastAuthor $oCreated.text = $gsEXml_DocProp_Created $oCompany.text = $gsEXml_DocProp_Company $oVersion.text = $gsEXml_DocProp_Version With $oDocProps .setAttribute("xmlns","urn:schemas-microsoft-com:office:office") .appendChild($oAuthor) .appendChild($oLastAuthor) .appendChild($oCreated) .appendChild($oCompany) .appendChild($oVersion) EndWith Return $oCallersWorkbook.appendChild($oDocProps) EndFunc Func EXml_CreateFile_OfficeDocumentSettings($oCallersXML, $oCallersWorkbook) With $oCallersXML Local $oOfficeDocumentSettings = .createElement("OfficeDocumentSettings") Local $oAllowPNG = .createElement("AllowPNG") EndWith With $oOfficeDocumentSettings .setAttribute("xmlns","urn:schemas-microsoft-com:office:office") .appendChild($oAllowPNG) EndWith Return $oCallersWorkbook.appendChild($oOfficeDocumentSettings) EndFunc Func EXml_CreateFile_ExcelWorkbook($oCallersXML, $oCallersWorkbook) With $oCallersXML Local $oExcelWorkbook = .createElement("ExcelWorkbook") Local $oWindowHeight = .createElement("WindowHeight") Local $oWindowWidth = .createElement("WindowWidth") Local $oWindowTopX = .createElement("WindowTopX") Local $oWindowTopY = .createElement("WindowTopY") Local $oProtectStructure = .createElement("ProtectStructure") Local $oProtectWindows = .createElement("ProtectWindows") EndWith $oWindowHeight.text = 8160 $oWindowWidth.text = 21570 $oWindowTopX.text = 0 $oWindowTopY.text = 0 $oProtectStructure.text = "False" $oProtectWindows.text = "False" With $oExcelWorkbook .setAttribute("xmlns","urn:schemas-microsoft-com:office:excel") .appendChild($oWindowHeight) .appendChild($oWindowWidth) .appendChild($oWindowTopX) .appendChild($oWindowTopY) .appendChild($oProtectStructure) .appendChild($oProtectWindows) EndWith Return $oCallersWorkbook.appendChild($oExcelWorkbook) EndFunc Func EXml_CreateFile_Styles($oCallersXML, $oCallersWorkbook) With $oCallersXML Local $oStyles = .createElement("Styles") Local $oStyle = .createElement("Style") Local $oAlignment = .createElement("Alignment") $oAlignment.setAttribute("ss:Vertical","Bottom") Local $oBorders = .createElement("Borders") Local $oFont = .createElement("Font") $oFont.setAttribute("ss:FontName","Calibri") $oFont.setAttribute("x:Family","Swiss") $oFont.setAttribute("ss:Size","11") $oFont.setAttribute("ss:Color","#000000") Local $oInterior = .createElement("Interior") Local $oNumberFormat = .createElement("NumberFormat") Local $oProtection = .createElement("Protection") EndWith With $oStyle .setAttribute("ss:ID","Default") .setAttribute("ss:Name","Normal") .appendChild($oAlignment) .appendChild($oBorders) .appendChild($oFont) .appendChild($oInterior) .appendChild($oNumberFormat) .appendChild($oProtection) EndWith $oStyles.appendChild($oStyle) Return $oCallersWorkbook.appendChild($oStyles) EndFunc Func EXml_AddCell_CreateWorkSheet($oCallersXML,$sCallersWorkSheetName) With $oCallersXML Local $oWorkSheet = .createElement("Worksheet") Local $oTable = .createElement("Table") EndWith $oWorkSheet.setAttribute("ss:Name",$sCallersWorkSheetName) With $oTable .setAttribute("ss:ExpandedColumnCount",0) .setAttribute("ss:ExpandedRowCount",0) .setAttribute("x:FullColumns",1) .setAttribute("x:FullRows",1) .setAttribute("ss:DefaultColumnWidth",60) .setAttribute("ss:DefaultRowHeight",15) EndWith $oWorkSheet.appendChild($oTable) Return $oWorkSheet EndFunc Func EXml_AddCell_CreateRow($oCallersXML,$oCallersTable,$iCallersCellRow) Local $oRow = $oCallersXML.createElement("Row") With $oRow .setAttribute("ss:AutoFitHeight",0) .setAttribute("ss:Index",$iCallersCellRow) EndWith If Number($oCallersTable.getAttribute("ss:ExpandedRowCount")) < $iCallersCellRow Then $oCallersTable.setAttribute("ss:ExpandedRowCount",$iCallersCellRow) EndIf Return $oRow EndFunc Func EXml_AddCell_CreateCell($oCallersXML,$oCallersTable,$iCallersCellCol,$sCallersData) Local $oCell = $oCallersXML.createElement("Cell") Local $oData = $oCallersXML.createElement("Data") With $oData .setAttribute("ss:Type","String") .text = $sCallersData EndWith With $oCell .setAttribute("ss:Index",$iCallersCellCol) .appendChild($oData) EndWith If Number($oCallersTable.getAttribute("ss:ExpandedColumnCount")) < $iCallersCellCol Then $oCallersTable.setAttribute("ss:ExpandedColumnCount",$iCallersCellCol) EndIf Return $oCell EndFunc Func EXml_AddCell_UpdateCell($oCallersCell,$sCallersCellData) With $oCallersCell.selectSingleNode("./Data") .text = $sCallersCellData EndWith EndFunc #endregion INTERNAL Debugging is still required when working with > 1 Sheets.
Things to add...styles on sheets, rows, cells.
-
Wombat reacted to Gianni in Need to creative minds on this...
Hi Wombat
it happens that if you are using win7 x64 there are 2 version of IE on your system, 64 and 32 bit versions, well, if this is your case, be aware that some problems arise if you run the 64 bit version in conjuction with some plugins, (i had problems with java runtime 6.xx & IE10 x64 for example).
In my case, i solved forcing the use of ie10 x32.
just make a link that points to the 32bit version instead of the 64bit.
i hope this may help.
bye