Bonjour,
je tente de modifier un fichier word sur le serveur
la methode COM est nouvelle pour moi j'aurais besoin de conseils
voici le code utilisé :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
//1. Instanciate Word
//com_load_typelib('Word.Application');
$word = @new COM("word.application") or die("Unable to instantiate Word");
//2. specify the MS Word template document (with Bookmark TODAYDATE inside)
$template_file = $_SERVER['DOCUMENT_ROOT']."\test\test.doc";
//3. open the template document
$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 = $_SERVER['DOCUMENT_ROOT']."\test\test.doc";
$word->Documents[1]->SaveAs($new_file);
//8. free the object
$word->Quit();
$word->Release();
$word = null; |
avec l'erreur suivante
PHP Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft Word<br/><b>Description:</b> Commande non disponible : aucun document n'est ouvert.' in D:\WWW\emm\www\test\test.php:27
Stack trace:
#0 D:\WWW\emm\www\test\test.php(27): unknown()
#1 {main}
thrown in D:\WWW\emm\www\test\test.php on line 27
cela concerne :
$objBookmark = $word->ActiveDocument->Bookmarks($bookmarkname);
Merci de votre aide
Partager