Page 1 of 1

Use PHP/MySQL to ouput to a MS word mail merge

Posted: Wed Mar 18, 2009 11:09 am
by squish
I have no idea if this can be done or not. But here is my problem.

I am trying to develop a PHP/MySQL solution for someone here that will make their life much much easier.

Basically, this user has a MS Word template for a series of letters that get sent out to employees based on their attendance record (e.g. if they don't show up, they get a warning letter). We call it a "no show". This word template has all the formatting and text needed for the letter, but has mail merge fields that insert things like the date of the incident, employee name, their supervisor, address etc etc. The SOURCE file for this mail merge is simply another Word document with a table in it that holds all the needed fields. She has to look up the employee's information, type it into the SOURCE file field by field, and THEN hit the merge button.

As you can imagine, having to do this 20-25 times a week is not fun.

So I've already setup a PHP/MySQL solution for the user so that all of the required information for each "no show" incident is entered and stored in a MySQL database that also holds employee information. The idea here is, for each no show incident there will be a link next to it where all she has to do is click it and it will open up the letter template word document and automatically insert all of the information (incident date, employee info etc.). Basically, I'm trying to do a mail merge using PHP!

I am pretty good with PHP/MySQL stuff but have never done any integration with Word. I'm hoping you experts here might be able to point my in the right direction!

Thanks :D

Re: Use PHP/MySQL to ouput to a MS word mail merge

Posted: Wed Mar 18, 2009 12:52 pm
by atonalpanic
It might not be a possibility for you, but why don't you create the template in HTML, fill them in
with data from MySQL by using PHP and just print it that way?

Alternatively, the user could just download the a CSV file with the info in it and load it into word. I believe CSV is an option for mail merge. Then you could essentially have x number of templates and split the CSV files into categories based on that. Then load em into word and watch it roar.

I'm also sure that there is a direct way to do this because on job posting sites they can obtain all your info (phone number,address,years of experience,last job) from your resume just by uploading it. I don't know anything about this method, though.

Re: Use PHP/MySQL to ouput to a MS word mail merge

Posted: Wed Mar 18, 2009 2:13 pm
by php_east
squish wrote:The idea here is, for each no show incident there will be a link next to it where all she has to do is click it and it will open up the letter template word document and automatically insert all of the information (incident date, employee info etc.). Basically, I'm trying to do a mail merge using PHP!
if it is of any help, some major popular html editors have word format handling capability, where you can cut and paste word documents right into it.

given that you can insert perhaps insert php vars into this tempate somehow, it would be then a matter of just using the editors insert capabilty , typically called insertHTML(), which will then insert the already filled word document.

then click send :) ( into your php mailer )

Re: Use PHP/MySQL to ouput to a MS word mail merge

Posted: Wed Mar 18, 2009 2:17 pm
by squish
Thanks for the ideas!

You are right, it might be simpler just to create the template via HTML and insert the variables with PHP returning an HTML page with formatted text.

So I've set that up... but now the problem is...how do I export that text into a word document while keeping all formatting?

Basically I have:

Code: Select all

"Letter text is here blah blah with variables included looks great!!!"
 
<link>Generate MS Word Document</link>
I'd like for the user to just click that link and have a word document open or ask to be saved.

Re: Use PHP/MySQL to ouput to a MS word mail merge

Posted: Wed Mar 18, 2009 2:23 pm
by php_east
i have seen a commercial html <> word php converter. have no experience using it.