Freedom1 Posted August 14, 2008 Posted August 14, 2008 (edited) Hello All, I've been looking at how to print from AutoIt using Word.au3. I can create/open the document, but when it comes to filling in the header with the title, the body with text, I'm at a loss. In the help file I saw $oDoc.Range.Text = "This is some text to print." How do I find out about ...Range.Text....? How do I find where the title is to go in the header? ($oDoc.Header.Title.Text = "This is the Title")??? Probably the most difficult part of this task is to create a 3 column table. The first row will be column headings in bold. I have an array that I want to place in 50 rows following the heading. I need to "snake" the array over the 3 columns. Array entries 1 -50 in 1st column, entries 51 - 100 in column 2, entries 101 - 150 in column 3. Print the page, clear and refill the table with the rest of the array. Can this be done in AutoIt using Word.au3? Is there an easier way? Can someone provide examples and more documentation for Word.au3?? Thanks, Freedom1 Edited August 15, 2008 by Freedom1
Freedom1 Posted August 15, 2008 Author Posted August 15, 2008 BUMP! Can anyone post an example (complete report)?
Andreik Posted August 15, 2008 Posted August 15, 2008 Look in help file COM Reference, maybe you will find what you want. PS: Use links for more info.
martin Posted August 15, 2008 Posted August 15, 2008 Hello All,I've been looking at how to print from AutoIt using Word.au3. I can create/open the document, but when it comes to filling in the header with the title, the body with text, I'm at a loss. In the help file I saw $oDoc.Range.Text = "This is some text to print." How do I find out about ...Range.Text....?How do I find where the title is to go in the header? ($oDoc.Header.Title.Text = "This is the Title")???Probably the most difficult part of this task is to create a 3 column table. The first row will be column headings in bold. I have an array that I want to place in 50 rows following the heading. I need to "snake" the array over the 3 columns. Array entries 1 -50 in 1st column, entries 51 - 100 in column 2, entries 101 - 150 in column 3. Print the page, clear and refill the table with the rest of the array.Can this be done in AutoIt using Word.au3? Is there an easier way?Can someone provide examples and more documentation for Word.au3??Thanks,Freedom1I can't help with Word.au3 but I would expect someone could help with that. Making bold headings and 3 columns of data, with boxes around the text, lines and so on is quite simple with my print udf using a dll. See my signature. Obviously you don't want to abandon the work you have done so far but if all else fails it is an alternative. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Freedom1 Posted August 19, 2008 Author Posted August 19, 2008 Martin, Yes, I'll be looking into your UDF. I see that your AutoIt file has a lot of comments. Are there any examples of a programs that print a report. An example would give me a jump start into utilizing your UDF. Thanks, Freedom1
martin Posted August 20, 2008 Posted August 20, 2008 Martin, Yes, I'll be looking into your UDF. I see that your AutoIt file has a lot of comments. Are there any examples of a programs that print a report. An example would give me a jump start into utilizing your UDF. Thanks, Freedom1There's an example in the first post for my udf which includes most o fthe things you might need in a report. Here's another small example which I use to print out a log for a month to keep track of when my cat has been fed so he doesn't con people into feeding him too much. Lacking in comments though. CODE #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=catfood.ico #AutoIt3Wrapper_outfile=CatFedForm.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include "printmgv2.au3" #include <date.au3> FileInstall("printmg.dll",@ScriptDir & "\",0) #Region ### START Koda GUI section ### Form=Q:\printing\CatFed.kxf $Form1 = GUICreate("Cat Meals Log", 256, 326, 447, 200) GUISetBkColor(0xD4D0C8) $CmbPrinters = GUICtrlCreateCombo("CmbPrinters", 16, 165, 217, 25) $Label1 = GUICtrlCreateLabel("Month", 16, 69, 34, 17) $Label2 = GUICtrlCreateLabel("Printer", 16, 146, 34, 17) $CmbMonths = GUICtrlCreateCombo("CmbMonths", 16, 88, 113, 25) $Label3 = GUICtrlCreateLabel("Select the details for the log, then click Print", 16, 16, 211, 17) $BtnPrint = GUICtrlCreateButton("Print", 80, 272, 83, 41, 0) $Label4 = GUICtrlCreateLabel("Year", 160, 69, 26, 17) $LabYear = GUICtrlCreateLabel("2008", 160, 91, 28, 17) $Group1 = GUICtrlCreateGroup("page layout", 16, 216, 217, 41) $RadioPortrait = GUICtrlCreateRadio("Portrait", 24, 232, 57, 17) $RadioLandscape = GUICtrlCreateRadio("Landscape", 141, 232, 79, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $hPrnDll, $prnErr $hPrnDll = _PrintDllStart($prnErr) If $hPrnDll = -1 Then MsgBox(262144, "ERROR with Print Dll", $prnErr) Exit EndIf ;MsgBox(0,'printmg version',_Printversion($hPrnDll,1)) #Region set months on combo ;allow this month or up to 2 months ahead. Global $Mlist, $Months = StringSplit("January|February|March|April|May|June|July|August|September|October|November|December", '|') Global $mm = @MON, $monthnum = @MON For $n = 0 To 4 If $mm + $n > 12 Then $mm = 1 - $n $Mlist &= '|' & $Months[$mm + $n] ; If $n < 2 Then $Mlist &= '|' Next GUICtrlSetData($CmbMonths, $Mlist, $Months[@MON]) GUICtrlSetData($LabYear, @YEAR) #EndRegion set months on combo #Region set printers Global $printers = _PrintListPrinters($hPrnDll) If @error = 0 Then ;MsgBox(0,'list = ',$printers) EndIf GUICtrlSetData($CmbPrinters, '|' & $printers, _PrintGetPrinter($hPrnDll)) #EndRegion set printers Global $keepGoing = True Global $yearnum = @YEAR While $keepGoing $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE $keepGoing = False Case $CmbMonths $selmon = GUICtrlRead($CmbMonths) For $n = 1 To 12 If $Months[$n] = $selmon Then $monthnum = $n If $n < @MON Then $yearnum = @YEAR + 1 Else $yearnum = @YEAR EndIf GUICtrlSetData($LabYear, $yearnum) ExitLoop EndIf Next Case $CmbPrinters _PrintSelectPrinter($hPrnDll,GUICtrlRead($CmbPrinters)) Case $BtnPrint printlog($monthnum, GUICtrlRead($LabYear), $yearnum, GUICtrlRead($RadioPortrait) = $GUI_CHECKED) EndSwitch WEnd _PrintDllClose($hPrnDll) Func printlog($pmon, $pyear, $pprinter, $pPortrait) _PrintSelectPrinter($hPrnDll, $pprinter) If $pPortrait Then _PrintPageOrientation($hPrnDll, 1) Else _PrintPageOrientation($hPrnDll, 0) EndIf _PrintStartPrint($hPrnDll) $Xmargin = _PrintGetXOffset($hPrnDll) + 50 $Ymargin = _PrintGetYOffset($hPrnDll) $pght = _PrintGetpageheight($hPrnDll) - $Ymargin $pgwd = _PrintGetpageWidth($hPrnDll) - $Xmargin _PrintSetFont($hPrnDll, "Arial", 8) $Lineht = Int(1.5 * _PrintGetTextHeight($hPrnDll, "A")) $NoDays = _DateDaysInMonth($pyear, $pmon) _PrintSetFont($hPrnDll, "Arial", 12, 0, "bold") _PrintText($hPrnDll, "Biggles has been fed", $Xmargin , $Lineht * 1.5) _PrintText($hPrnDll, _DateToMonth($pmon) & " " & $pyear, $Xmargin + 100, $Lineht * 3) _PrintSetFont($hPrnDll, "Arial", 8) $startlineY = 5 * $Lineht $Mostwid = 0;the longest line For $n = 1 To $NoDays $dd = _DateToDayOfWeek($pyear, $pmon, $n) $day = _DateDayOfWeek($dd) $sp = StringFormat("%3d %s", $n, $day) $swid = _PrintGetTextWidth($hPrnDll, $sp) If $swid > $Mostwid Then $Mostwid = $swid _PrintText($hPrnDll, $sp, $Xmargin, $startlineY + $Lineht * $n) Next _PrintSetLineWid($hPrnDll, 2) _PrintSetLineCol($hPrnDll, 0) $LIneEnd = $Mostwid + 300 For $n = 1 To $NoDays + 1 $Ypos = $startlineY + $Lineht * ($n - 0.2) + 3 If $n = 1 Then $YTop = $Ypos If $n = $NoDays + 1 Then $Ybot = $Ypos _PrintLine($hPrnDll, $Xmargin, $Ypos, $LIneEnd, $Ypos) Next $tickWid = ($LIneEnd - ($Xmargin + $Mostwid + 20)) / 2 _PrintText($hPrnDll, "a.m.", $LIneEnd - 2 * $tickWid + 30, $startlineY) _PrintText($hPrnDll, "p.m.", $LIneEnd - $tickWid + 30, $startlineY) _Printline($hPrnDll, $Xmargin, $YTop, $Xmargin, $Ybot) _Printline($hPrnDll, $Xmargin + $Mostwid + 20, $YTop, $Xmargin + $Mostwid + 20, $Ybot) _Printline($hPrnDll, $LIneEnd - $tickWid, $YTop, $LIneEnd - $tickWid, $Ybot) _Printline($hPrnDll, $LIneEnd, $YTop, $LIneEnd, $Ybot) _PrintEndPrint($hPrnDll) EndFunc ;==>printlog Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now