Sign in to follow this  
Followers 0
Peter89

Best way to create and print a document

12 posts in this topic

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


 

Share this post


Link to post
Share on other sites



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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

Ok, I've found the reason myself.. :)

Share this post


Link to post
Share on other sites

So after _Word_Create the MS Word GUI pops up?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Great. And the problem was?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites

So you don't want to underline the text but insert a line by itself?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#11 ·  Posted (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 by Peter89

Share this post


Link to post
Share on other sites

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0