データベースに格納されている画像をタイプフィールドと共に取得しました。その画像をAまたはBと言います。これらの画像を単語テンプレート、imgPlaceholder1という名前のフィールドに追加しようとしていますイメージの種類に応じてimgPlaceholder2を指定します。私の現在のコード:単語の複数の画像を追加する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();
}
今、コードは動作しますが、何か変です型を無視し、すべてを最初のプレースホルダに引っ張ります。私は選択 - >検索 - >テキストのためにそれを信じていますが、私は選択をクリアするか、何か新しいものを検索するように強制する方法は知られていません。 また、ドキュメントを保存して閉じてから、2番目のタイプのイメージを挿入しようとしましたが、結果は同じです。すべての画像が最初のプレースホルダーになります。