Jump to content

Recommended Posts

Posted

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


 

Posted

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

 

Posted

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

Posted

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

 

Posted

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)
Posted

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

 

Posted

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

 

Posted

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

 

Posted

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

 

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
Posted

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

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...