Topher Posted February 15, 2012 Share Posted February 15, 2012 Hi, I'm trying to print out a simple invoice. I assume the _Word commands are the way to go. But to be honest they are baffling me and the examples aren't helping. Can someone post a small example that prints a couple of lines in differing fonts? This would be most appreciated. [left][hr] $mood = "whimsy" $mode = "confused" $randomChaos = True Do Something() Until $Tired[/left][left]Reflex (Arcade game)[/left][left]IX (Board game)[/left][left]The Word Game (Word game)[/left][left]Plastic Sliding Squares Puzzle (Puzzle)[/left] Link to comment Share on other sites More sharing options...
MrMitchell Posted February 15, 2012 Share Posted February 15, 2012 Hi and welcome. Your best bet would be to read through the tutorials and get a basic knowledge of AutoIt as well as how Objects/COM works. The Help File provides working examples for how to use _WordDocPrint(). Link to comment Share on other sites More sharing options...
Topher Posted February 15, 2012 Author Share Posted February 15, 2012 The Help File provides working examples for how to use _WordDocPrint().In the examples I see they show how to print a single line.I'm probably slow but I can not extrapolate how to do multiple lines from this.Also unsure of how to set/change fonts for printing.I have written a few scripts in Autoit, this latest one quite lengthy. I have dragged myself through the learning curve and have been able to use the help file for figuring out what I needed along the way. I am not lazy but in this area I am stuck.One straightforward example would send me on my way.Thanks [left][hr] $mood = "whimsy" $mode = "confused" $randomChaos = True Do Something() Until $Tired[/left][left]Reflex (Arcade game)[/left][left]IX (Board game)[/left][left]The Word Game (Word game)[/left][left]Plastic Sliding Squares Puzzle (Puzzle)[/left] Link to comment Share on other sites More sharing options...
BrewManNH Posted February 15, 2012 Share Posted February 15, 2012 I'm guessing, from reading the help file for _WordDocPrint, that you can't specify lines to print (pages only), or change the font of the lines you're printing. It looks like you're going to need to set up your document with the correct fonts, and what you want printed in the correct format to print them the way you want them. Once you get to that point, you might as well just print them from Word and use a mail merge. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator Link to comment Share on other sites More sharing options...
Topher Posted February 15, 2012 Author Share Posted February 15, 2012 So you are saying there is no way to print more than a single line without training the user in how to use Word? [left][hr] $mood = "whimsy" $mode = "confused" $randomChaos = True Do Something() Until $Tired[/left][left]Reflex (Arcade game)[/left][left]IX (Board game)[/left][left]The Word Game (Word game)[/left][left]Plastic Sliding Squares Puzzle (Puzzle)[/left] Link to comment Share on other sites More sharing options...
BrewManNH Posted February 15, 2012 Share Posted February 15, 2012 The example script in the help file doesn't show you how to print a single line, it creates a document with a single line in it and then prints it. As to your second question, no you have to know what you're doing to be able to do what you want in a Word document, and it's all pretty basic stuff. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator Link to comment Share on other sites More sharing options...
Topher Posted February 15, 2012 Author Share Posted February 15, 2012 The example script in the help file doesn't show you how to print a single line, it creates a document with a single line in it and then prints it.Then how would I create a document with multiple lines and then print it?As to your second question, no you have to know what you're doing to be able to do what you want in a Word document, and it's all pretty basic stuff.My knowing Word and the end user knowing Word are two very different things.It sounds as if the best solution is to use a language that has printing capabilities to read and print from the data file. This I could call from the main script.It would be almost seamless and the end user need only learn the program itself. [left][hr] $mood = "whimsy" $mode = "confused" $randomChaos = True Do Something() Until $Tired[/left][left]Reflex (Arcade game)[/left][left]IX (Board game)[/left][left]The Word Game (Word game)[/left][left]Plastic Sliding Squares Puzzle (Puzzle)[/left] Link to comment Share on other sites More sharing options...
BrewManNH Posted February 15, 2012 Share Posted February 15, 2012 Then how would I create a document with multiple lines and then print it?I would assume you take this line : $oDoc.Range.Text = "This is some text to print." and expand it to include all of your text.My knowing Word and the end user knowing Word are two very different things.It sounds as if the best solution is to use a language that has printing capabilities to read and print from the data file. This I could call from the main script.It would be almost seamless and the end user need only learn the program itself.That would be Word, otherwise you're just reinventing Word to access Word, seems counter-productive to me. Teaching a person to Open/Create a document, type some stuff into it, change fonts, and then print it is all pretty basic things, which Word does quite well. Automating that would mean they'd have to type in a document name to open, or create a new one, have a place to enter text that allows you to change its format (font size, bold, color, etc.), then have some way of printing it (CTRL-P in Word). Seems like that would take less time to do IN Word than writing a script that allows you to do that. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator Link to comment Share on other sites More sharing options...
Topher Posted February 15, 2012 Author Share Posted February 15, 2012 I would assume you take this line : $oDoc.Range.Text = "This is some text to print." and expand it to include all of your text.I was afraid you were going to say that. That's going to be one long variable.Still leaves me with the font problem though.Think I'm going to have to go with another language (Basic or C++ most likely) to handle the printing part. [left][hr] $mood = "whimsy" $mode = "confused" $randomChaos = True Do Something() Until $Tired[/left][left]Reflex (Arcade game)[/left][left]IX (Board game)[/left][left]The Word Game (Word game)[/left][left]Plastic Sliding Squares Puzzle (Puzzle)[/left] Link to comment Share on other sites More sharing options...
MrMitchell Posted February 15, 2012 Share Posted February 15, 2012 (edited) Is this something like what you're looking for? #include <Word.au3> $oWordApp = _WordCreate ("C:tempTest.doc") $oDoc = _WordDocGetCollection ($oWordApp, 0) $oWordApp.Selection.TypeText("This is some text to print.") $oWordApp.Selection.Font.Name = "Tahoma" $oWordApp.Selection.Font.Size = 36 $oWordApp.Selection.TypeText("This is some more text to print and should be Tahoma size 36.") $oWordApp.Selection.TypeParagraph $oWordApp.Selection.Font.Name = "Arial Black" $oWordApp.Selection.Font.Size = 24 $oWordApp.Selection.TypeText("This is some more text to print and should be Arial Black size 24.") $oWordApp.Selection.TypeParagraph _WordTypeText("Text to write using the function", "Comic Sans", 72) _WordDocPrint ($oDoc) _WordQuit ($oWordApp, 0) Func _WordTypeText($text, $fontName, $fontSize, $fNewLine = 1) $oWordApp.Selection.Font.Name = $fontName $oWordApp.Selection.Font.Size = $fontSize $oWordApp.Selection.TypeText($text) If $fNewLine = 1 Then $oWordApp.Selection.TypeParagraph EndFunc Edit: Added simple example of function Edited February 15, 2012 by MrMitchell Link to comment Share on other sites More sharing options...
Topher Posted February 15, 2012 Author Share Posted February 15, 2012 Is this something like what you're looking for? #include <Word.au3> $oWordApp = _WordCreate ("C:tempTest.doc") $oDoc = _WordDocGetCollection ($oWordApp, 0) $oWordApp.Selection.TypeText("This is some text to print.") $oWordApp.Selection.Font.Name = "Tahoma" $oWordApp.Selection.Font.Size = 36 $oWordApp.Selection.TypeText("This is some more text to print and should be Tahoma size 36.") $oWordApp.Selection.TypeParagraph $oWordApp.Selection.Font.Name = "Arial Black" $oWordApp.Selection.Font.Size = 24 $oWordApp.Selection.TypeText("This is some more text to print and should be Arial Black size 24.") $oWordApp.Selection.TypeParagraph _WordTypeText("Text to write using the function", "Comic Sans", 72) _WordDocPrint ($oDoc) _WordQuit ($oWordApp, 0) Func _WordTypeText($text, $fontName, $fontSize, $fNewLine = 1) $oWordApp.Selection.Font.Name = $fontName $oWordApp.Selection.Font.Size = $fontSize $oWordApp.Selection.TypeText($text) If $fNewLine = 1 Then $oWordApp.Selection.TypeParagraph EndFunc Edit: Added simple example of function It gives me an error when I try to run it. However it looks like an example I can learn from. Thank you very much. [left][hr] $mood = "whimsy" $mode = "confused" $randomChaos = True Do Something() Until $Tired[/left][left]Reflex (Arcade game)[/left][left]IX (Board game)[/left][left]The Word Game (Word game)[/left][left]Plastic Sliding Squares Puzzle (Puzzle)[/left] Link to comment Share on other sites More sharing options...
Topher Posted February 15, 2012 Author Share Posted February 15, 2012 --> Word.au3 Error from function _WordCreate (Word Object Creation Failed)Could this be because I use OpenOffice rather than Word on this computer? [left][hr] $mood = "whimsy" $mode = "confused" $randomChaos = True Do Something() Until $Tired[/left][left]Reflex (Arcade game)[/left][left]IX (Board game)[/left][left]The Word Game (Word game)[/left][left]Plastic Sliding Squares Puzzle (Puzzle)[/left] Link to comment Share on other sites More sharing options...
Developers Jos Posted February 15, 2012 Developers Share Posted February 15, 2012 Could this be because I use OpenOffice rather than Word on this computer? Sounds very likely that Word Com objects aren't installed when Word isn't installed. SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
MrMitchell Posted February 15, 2012 Share Posted February 15, 2012 Link to comment Share on other sites More sharing options...
Topher Posted February 16, 2012 Author Share Posted February 16, 2012 Sounds very likely that Word Com objects aren't installed when Word isn't installed. I know that sounds silly, but I always thought of openoffice as a complete substitute for Word.Anyway, after much rooting around I found an old (2003) version of Word and installed it.Everything works fine now. Thank you for your example, I will begin molding it to my script in the morning.Do you know if there is a list of the .selection variable/functions somewhere? [left][hr] $mood = "whimsy" $mode = "confused" $randomChaos = True Do Something() Until $Tired[/left][left]Reflex (Arcade game)[/left][left]IX (Board game)[/left][left]The Word Game (Word game)[/left][left]Plastic Sliding Squares Puzzle (Puzzle)[/left] Link to comment Share on other sites More sharing options...
MrMitchell Posted February 16, 2012 Share Posted February 16, 2012 Do you know if there is a list of the .selection variable/functions somewhere?In Word... open Word and I believe press ALT+F11 then once the Editor opens up press F2 to open the Object Browser. Link to comment Share on other sites More sharing options...
Topher Posted February 16, 2012 Author Share Posted February 16, 2012 In Word... open Word and I believe press ALT+F11 then once the Editor opens up press F2 to open the Object Browser.Wow, that is a lot to take in.Thank you very much. [left][hr] $mood = "whimsy" $mode = "confused" $randomChaos = True Do Something() Until $Tired[/left][left]Reflex (Arcade game)[/left][left]IX (Board game)[/left][left]The Word Game (Word game)[/left][left]Plastic Sliding Squares Puzzle (Puzzle)[/left] Link to comment Share on other sites More sharing options...
MrMitchell Posted February 16, 2012 Share Posted February 16, 2012 There's a reference in MSDN online, use whichever your prefer: http://msdn.microsoft.com/en-us/library/aa223084%28v=office.11%29.aspx Link to comment Share on other sites More sharing options...
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