Jump to content

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


kudrow
 Share

Recommended Posts

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!

Link to comment
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)
Link to comment
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 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
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 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

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