Sign in to follow this  
Followers 0
kudrow

Auto create pdf files using a word template and strings from file

5 posts in this topic

Hello Everyone,

I searched around on the forums but I am not sure I am searching the right words to find what I am looking for. So I will just explain what I am trying to do and hopefully someone will point me in the right direction.

Basically I have an excel spread sheet with data in it that I would like to auto-fill "place holders" with on a word template. So for each cell on row 1, there is a matching place holder in the template that will be replaced with the data from the cell. Once the placement is done I can save as a pdf. Anyone have any thoughts?

Thanks!

Share this post


Link to post
Share on other sites



Well I am trying a few things out to see if I can make some progress. Currently I am reading in an .rtf and using StringReplace to change values on placeholders. The problem is the change is not saved with FileWrite and the FileClose. I do know the placeholder that I want to replace exists by checking it with StringRegExp. Below is my code, what am I missing? 

Local $file = FileOpen("pwf.rtf", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

$filetoread = FileRead($file)
$replace = StringReplace ($filetoread, "id_1", "My Text")

FileWrite ($file, $replace)
FileClose($file)

Share this post


Link to post
Share on other sites

Word allows to merge data from a database (yes, Excel can act as a database) into a document. This could then be exported as PDF.

I have never used it myself but when you search the forum for "mailmerge" you will get some hits.


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

Thank you for the info. I am trying to avoid actually opening any other programs during the process. Is there anything wrong with my code above?

Share this post


Link to post
Share on other sites

The error is caused by this line:

FileOpen("pwf.rtf", 0)

This opens the file in read mode.


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