Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 1st, 2008, 6:13 PM   #1
SavageProg
Newbie
 
Join Date: May 2008
Posts: 2
Rep Power: 0 SavageProg is on a distinguished road
Lightbulb User Input to Fill in Bookmarks in Word Doc

OK, my company uses 2 word docs to process orders. I was asked to see if I could design a page that the user could input their info, and it would in turn auto populate the fields on the template word doc "using bookmarks of course" and then saving it as a seperate doc to preserve the template. I dont really know where to start writing a PHP script to do this interaction with word. Any suggestions? My idea...

1. Create a word macro...

Sub BkmkNumber1()Selection.GoTo What:=wdGoToBookmark, Name:="name"End Sub

2. The script...

$userfile="C:/temp/userfile.doc";

$first=<?php>  $_POST["name"]; <?>
$second=<?php>  $_POST["address"]; <?>
$third=<?php>  $_POST["phone"]; <?>


$word=new COM("Word.Application") or die("Cannot start MS Word");

$word->visible = 1 ;
$word->Documents->Open($userfile);


$word->Application->Run("BkmkNumber1");
$word->Selection->TypeText($first);
$word->Application->Run("BkmkNumber2");
$word->Selection->TypeText($second);
$word->Application->Run("BkmkNumber3");
$word->Selection->TypeText($third);

$word->Application->ActiveDocument->Saved=True;

$word->Quit();
$word->Release();
$word = null;
?>

But i have no idea how to do a save as on the doc after its done or if this would even work.
SavageProg is offline   Reply With Quote
Old Jun 2nd, 2008, 1:00 PM   #2
SavageProg
Newbie
 
Join Date: May 2008
Posts: 2
Rep Power: 0 SavageProg is on a distinguished road
Lightbulb Re: User Input to Fill in Bookmarks in Word Doc

OK, I did some research and found out the correct method for doing this. Now I just gotta get it to work. Below is the php page I have so far. It initializes word, I know because winword.exe shows up as a process, but it gets stuck and wont complete. Any ideas where I went wrong?

<?php
$name = $_POST["name"];

$word = new COM("Word.Application") or die("Unable to instantiate Word");

$template_file = "C:\Documents and Settings\user\My Documents\sample\sample.doc";
$word->visible=1;

$word->Documents->Open($template_file);

substitution)
$bookmarkname = "text45";
$objBookmark = $word->ActiveDocument->Bookmarks($bookmarkname);
$range = $objBookmark->Range;

$range->Text = $name;

$new_file = "c:\reminder_new.doc";
$word->Documents[1]->SaveAs($new_file);

$word->Quit();
$word->Release();
$word = null;
?>

Obviously, text45 is the bookmark where the name is stored on the template.
SavageProg is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
input data from user into array lilmul123 C++ 5 May 26th, 2006 10:29 AM
User input jayme C++ 38 Nov 25th, 2005 8:27 PM
Should i use fgets to set user input to a variable? linuxpimp20 C 3 Nov 25th, 2005 6:04 AM
User Input for Number Format ericelysia1 Java 0 Jul 21st, 2005 4:41 PM
Problem read'ing from file and user input jmsilver Bash / Shell Scripting 3 May 20th, 2005 3:35 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:50 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC