Solved

MS Word Template for PHP/MySQL

Posted on 2004-04-16
13
752 Views
Last Modified: 2008-03-17
Could anybody do a small sample regular Word document with anchors (is that what they are called?) so that I could propogate those with MySQL entries? IE:

Hello {firstname}{lastname},

Thanks for your interest in our product.

Where {firstname}{lastname} would be values from a row of MySQL and the columns firstname, lastname.
0
Comment
Question by:drakkarnoir
13 Comments
 
LVL 12

Accepted Solution

by:
venkateshwarr earned 400 total points
Comment Utility
I did not get your question.

If you want to create a word document... the following links have snippets that can help you.

http://www.programmershelp.co.uk/phpcreateword.php
http://www.phpbuilder.com/columns/yunus20031124.php3?page=2
0
 
LVL 7

Assisted Solution

by:madwax
madwax earned 100 total points
Comment Utility
<?php
$word = new COM("word.application") or die ("couldnt create an instance of word");
$word->visible = 1;
$word->Documents->Add();

//replace with your connection to database here...


$sql = "SELECT firstname,lastname FROM myTable WHERE id=X";
$result = mysql_query($sql);
$row = mysql_fetch_object($result);

$word->Selection->TypeText("Hello".$row->firstname." ".$row->lastname."\n\n Thanks for your interest in our product.");
$word->Documents[1]->SaveAs("sampleword.doc");
$word->Quit();
$word->Release();
$word = null;
?>
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
he means autotext, and i will try and give you a solutions by monday.
0
 

Author Comment

by:drakkarnoir
Comment Utility
Still here jkna_gunn?
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
yeah sorry, was a holiday here. ive not had a chance to look into it yet.
do you know how to create these "anchors" in word as ive not used that before.
0
 

Author Comment

by:drakkarnoir
Comment Utility
Nope, I'm not even sure if they are called anchors, I was just taking a guess with that word...
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:drakkarnoir
Comment Utility
Still here jkna_gunn?
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
im here but i need to find out how to do these "anchors" in word first.

worst comes to worst might just have to do a search replace on the strings.
0
 

Author Comment

by:drakkarnoir
Comment Utility
You mean bookmarks?

"To create a Bookmark in a MS Word document, click on Insert/Bookmark. You can highlight a word or sentence and make them a Bookmark."

So then using that idea, we just have to tell MS Word using COM+ to look for the bookmark, and select the range of it, and replace the value of it with our value:

<?php
$fullname = $firstname . $lastname;
$bookmarkname = "NAME";
$objBookmark = $word->ActiveDocument->Bookmarks($bookmarkname);
$range = $objBookmark->Range;
$range->Text = $fullname;
?>

0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
and that doesn't work?
0
 

Author Comment

by:drakkarnoir
Comment Utility
It does, I just thought you had a better way :)
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
not that i know of sorry :(
0
 

Author Comment

by:drakkarnoir
Comment Utility
Hmmmm, in that case, I'm going to have to award venkateshwarr with the points, as he pointed me to the link which spoke about that, and give some points to madwax for his input. Thanks for your participation jkna_gunn, I really apppreciated your help with my labeling question :)
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now