Peter89 Posted February 7, 2014 Posted February 7, 2014 Hi all, I'm looking for the best way using autoit to create,save and print a document. I've found some possibilities but im really not sure what would be the best solution for my requirements.So what i have and what i want to do: I have a GUI with inputfields, SQL-queries etc. I want to build one document template for a specific use case. Next i want to fill some fields using variables delivered from inputfields or sql results. After this the document should be saved under a new name and printed out. What do you guys think would be the best / easiest way to do this? Should i create a html form and fill the fields with auto it? Use any office UDF's? Create a PDF and print it using adobe reader commandline parameters to start the printjob? I don't have heavy requirements regarding the document and its layout. Just a Picture on the top and some text and lines below. I'm not an autoit expert and looking forward to your replies! THANKS a lot Best regards.. Peter
water Posted February 7, 2014 Posted February 7, 2014 Welcome to AutoIt and the forum! I think the solution depends on what is available on your computer. If MS Word is available you could manually create a template. Fill in the data using AutoIt and print the file. The Word UDF that comes with AutoIt will help. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Peter89 Posted February 7, 2014 Author Posted February 7, 2014 Hi Water! Thanks for your fast reply! Is it possible to perform this in the background so that it's not noticeable by the user? I guess this solution will not be very fast or am i wrong? For each document which will be generated word will open up the template.doc, fill in text, save as a new document and starts printing afterwards? I guess this would take a lot of time or am i wrong? Would it be faster to create a HTML (_IEDocWriteHTML) and fill in the Text using variables during this creation? Afterwards i would print the html files using "_FilePrint()"? Or is this a bad idea / solution? Peter
water Posted February 7, 2014 Posted February 7, 2014 Correct. The UDF uses COM so it ca run unnoticed by the user. Starting Word takes some time but creating a document, saving and printing shouldn't be too slow. What would be fast enough for a single doucment? To see how fast the Word UDF works you should try some of the sample scripts from the help file. I suggest _Word_DocPrint. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Peter89 Posted February 8, 2014 Author Posted February 8, 2014 Hi Water, ok your function is really great! Thanks a lot for it! But somehow i cant get word 2013 to proceed hidden =/ Global $oWord = _Word_Create(False) Global $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\kva.docx") $bearbeiter="Bearbeiter: Max Mustermann" ; Open test document read-only Global $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\kva.docx", Default, Default, True) If @error <> 0 Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace Example", _ "Error opening '.\Extras\Test.doc'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Word_DocFindReplace($oDoc, "Rechnungsnr.:", "Rechnungsnr.: " &$rechnungsnr) If @error <> 0 Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace", _ "Rechnungsnr" & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Word_DocFindReplace($oDoc, "Kundenname", $kundeVN&$kundeNN) If @error <> 0 Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace", _ "Kundenname" & @CRLF & "@error = " & @error & ", @extended = " & @extended)
water Posted February 8, 2014 Posted February 8, 2014 So after _Word_Create the MS Word GUI pops up? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
water Posted February 8, 2014 Posted February 8, 2014 Great. And the problem was? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Peter89 Posted February 8, 2014 Author Posted February 8, 2014 I called the _word_docopen 2 times after the _word_create. Removing the first one solved the problem Now everything works fine! But i have an additional question: How can i add a bottom border under a specific line? THX & best wishes.. Peter
water Posted February 8, 2014 Posted February 8, 2014 So you don't want to underline the text but insert a line by itself? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Peter89 Posted February 8, 2014 Author Posted February 8, 2014 (edited) The background regarding this topic is that i want to create a bill. I have multiple items or workpositions which can be selected in my GUI. I want to put the selected items into a array and write them into the word document. It should nearly look like this: Art-Nr Details Count Price ______________________________________________________________________ 1 ABCASKDJ 2 10,00 ______________________________________________________________________ 2 CKSKALJDLAS 1 2,00 ______________________________________________________________________ Edited February 8, 2014 by Peter89
water Posted February 8, 2014 Posted February 8, 2014 Something like this. Sets the border of every row of the first table in the document to "solid underline". Global $wdBorderBottom = -3 Global $wdLineStyleSingle = 1 $oTable = $oDoc.Tables.Item(1) ; grab the first table in the document For $oRow In $oTable.Rows $oRow.Borders($wdBorderBottom).LineStyle = $wdLineStyleSingle Next My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
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