Welcome Guest, Not a member yet? Register   Sign In
How to dispaly php variables in MS word in CI
#1

[eluser]zombica[/eluser]
H Guys does any body know how can i add edit MS word document through php variables data. Does any body know the bookmark technique in MS word to replace php variable values.

I am dying to find out the solution, because for the last couple of days i am unable to find not a single solution of this.

Thanx in advance.

Regards,
Zombica
#2

[eluser]Evil Wizard[/eluser]
Let me google that for you Wink
the second link looked of most relevance Creating Word Documents on the Fly
#3

[eluser]zombica[/eluser]
Hi Evil,
Thanx for helping me out, i have go through with this URL couple of times and the script written over here i so simple to understand. But the problem is this all these script using COM class of php throws this error.

Fatal error: Call to undefined method variant::Bookmarks().
What is the purpose of ActiveDocument over here.
After reading the template doc file it makes it read only file.

Code:
//1. Instanciate Word
    $word = new COM("word.application") or die("Unable to instantiate Word");
  
    //2. specify the MS Word template document (with Bookmark TODAYDATE inside)
    $template_file = "D:/doc/reminder.doc";
  
    //3. open the template document
    $template_file;
    $word->Documents->Open($template_file);
  
    //4. get the current date MM/DD/YYYY
    $current_date = date("m/d/Y");
  
    //5. get the bookmark and create a new MS Word Range (to enable text substitution)    
    $bookmarkname = "TODAYDATE";
    $objBookmark = $word->ActiveDocument->Bookmarks($bookmarkname);
    $range = $objBookmark->Range;
        
    //6. now substitute the bookmark with actual value
    $range->Text = $current_date;
        
    //7. save the template as a new document (c:/reminder_new.doc)
    $new_file = "D:/doc/reminder.doc";
    $word->Documents[1]->SaveAs($new_file);
        
    //8. free the object
    $word->Quit();
    $word->Release();
    $word = null;




Theme © iAndrew 2016 - Forum software by © MyBB