1

Given a microsoft word with form field, is there some api we can use to populate it? I need to do this at the backend of my php web application.

and, I have seen this link http://drewd.com/2007/01/25/reading-from-a-word-document-with-com-in-php

Is there a way to field up a form using the word com object?

william007
  • 17,375
  • 25
  • 118
  • 194

1 Answers1

0

This works fine for me:

<?php
com_load_typelib('Word.Application');
$word = new COM("word.application");
$word->Documents->Open('C:/Doc1.doc');
$word->Visible = 1;
$word->ActiveDocument->FormFields("Text1")->Result = "something";
$word->ActiveDocument->Close(false);
$word->Quit();
unset($word);
?>
ExternalUse
  • 2,053
  • 2
  • 25
  • 37
  • Hi for the FormFields("Text1"), how do you named the field? – william007 Mar 08 '13 at 13:25
  • Well, I suppose you have an existing document. Each Form field in Word has a name. Right-Click the Field -> Properties -> Field settings "Bookmark". Default is Text1, Text2, Textn – ExternalUse Mar 08 '13 at 13:31
  • Or loop through in php to check the names - pseudo code: foreach $word->....>FormFields as $field { echo (string) $field->Name } – ExternalUse Mar 08 '13 at 13:33
  • Hi, I got error for line $word->Documents->Open('C:/Doc1.doc');, it says Fatal error: Cannot pass parameter 1 by reference – william007 Mar 17 '13 at 17:25
  • Well, have you got a "Doc1.doc" word document in C:\?? You will have to take care of a tiny bit of work yourself... You may want to update your question with the code you are now trying to run. – ExternalUse Mar 18 '13 at 09:13