Word.application

peshkov

Новичок
Word.application

Помогите разобраться.

Извените Что здесь разместил код.

Есть файл example.doc после запуска скрипта создаеться новый документ и в нем вставлен текст "My example text here - Мой текст здесь"

Вопрос как сделать что бы текст вставлялся в таблицу или объясните почему когда создаешь новый документ WORD в него не вставляеться строчка "My example text here - Мой текст здесь"
Код:
<?php
require_once ("mswordClass.php");
$wordClass = new ms_word("d:/example.doc");
$newFile="d:/example_new.doc";
$newData = "My example text here - Мой текст здесь";
$wordClass->mswordAddData("EXAMPLEDATA",$newData);
$wordClass->mswordSave($newFile);
$wordClass->mswordClose();
$wordClass->mswordSend($newFile);
?>
<?php
if(!defined("MSWORD_LAYER")){
define("MSWORD_LAYER","msword");
class ms_word
{
var $word;
var $row = array();
function ms_word($template_file)
{
$this->template_file = $template_file;
if($this->template_file)
{
$this->word = new COM("word.application") or die("Unable to instantiate Word");
$this->word->Documents->Open($this->template_file);
}
else
return false;
}
function mswordAddData($bookmark, $newData)
{
if($this->word->ActiveDocument->Bookmarks->Exists($bookmark))
{
$objBookmark = $this->word->ActiveDocument->Bookmarks($bookmark);
$range = $objBookmark->Range;
$range->Text = $newData;
return true;
}else
return false;
}
function mswordSave($fileName)
{
if (file_exists($fileName)) unlink($fileName);
if ($this->word->Documents[1]->SaveAs($fileName)){
return true;
}else{
return false;
}
}
function mswordSend($fileName)
{
if (file_exists($fileName)){
header('Content-Type: application/msword');
header("Content-Disposition: attachment; filename=\"Reminder New.doc\"");
readfile($fileName);
}else{
return false;
}
}
function mswordClose(){
$this->word->Quit();
$this->word = null;
}
}
}
?>
 

planarik

Новичок
Посмотри в справке VBA. По моему bookmark там использовать не надо, обычним find. А если ты сделал EXAMPLEDATA закладкой, то тогда все понятно - у тебя меняется имя закладки а не сам текст. Могу ошибаться.
 
Сверху