![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: May 2008
Posts: 2
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#2 |
|
Newbie
Join Date: May 2008
Posts: 2
Rep Power: 0
![]() |
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. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| input data from user into array | lilmul123 | C++ | 5 | May 26th, 2006 9:29 AM |
| User input | jayme | C++ | 38 | Nov 25th, 2005 7:27 PM |
| Should i use fgets to set user input to a variable? | linuxpimp20 | C | 3 | Nov 25th, 2005 5:04 AM |
| User Input for Number Format | ericelysia1 | Java | 0 | Jul 21st, 2005 3:41 PM |
| Problem read'ing from file and user input | jmsilver | Bash / Shell Scripting | 3 | May 20th, 2005 2:35 PM |