0
我已經將幾個圖像與類型字段一起存儲在數據庫中,可以說它是A或B.我試圖將它們添加到單詞模板中,放入我命名爲imgPlaceholder1的字段中和imgPlaceholder2取決於圖像的類型。繼承人我目前的代碼:在word中添加多個圖像doc
$wordTable = new COM("Word.Application") or die("Unable to instanciate Word");
$wordTable->visible = 1;
$wordTable->Documents->Open("c:\template\file.doc");
try {
$query = "select id,path,type from uploads Where id = '$Id'";
$action = mysql_query($query) or die(mysql_error());
while($result = mysql_fetch_array($action)){
$type=$result['type'];
$path=$result['path'];
if($type=='A'){
$wordTable->Selection->Find->ClearFormatting();
$wordTable->Selection->Find->Text = 'imgPlaceholder1';
$wordTable->Selection->Find->Execute();
$wordTable->Selection->InlineShapes->AddPicture($path,False,True);
}
if($type=='B'){
$wordTable->Selection->Find->ClearFormatting();
$wordTable->Selection->Find->Text = 'imgPlaceholder2';
$wordTable->Selection->Find->Execute();
$wordTable->Selection->InlineShapes->AddPicture($path,False,True);
}
}
}
catch (Exception $e)
{
echo $e->getMessage();
}
現在,代碼工作,但它確實有點奇怪。它會忽略該類型並將所有內容拉入第一個佔位符。我相信它是因爲選擇 - >查找 - >文本,但我不知道如何清除選擇或迫使它搜索新的東西。 我也嘗試保存並關閉文檔,然後插入第二種類型的圖像,但結果是相同的。所有圖像都以第一個佔位符結束。