2017-07-10 9 views
0

Spire .NETを使用してテンプレート内のイメージを置換し、出力として保存するdocxファイル。私はそれを置き換えるために、以下のコードを使用します。私の問題は、MS Wordでイメージのイメージタイトルを設定する方法がわからないため、Spireがイメージの置き換え先を知ることです。Spire .NETがイメージを識別して新しいイメージに置き換える(検索する)ためにMS Wordのイメージのタイトルを設定する

Document document = new Document("template.docx"); 
//Loop through the paragraphs of the section 
foreach (Paragraph paragraph in document.Sections[0].Paragraphs) 
{ 
    //Loop through the child elements of paragraph 
    foreach (DocumentObject docObj in paragraph.ChildObjects) 
    { 
     if (docObj.DocumentObjectType == DocumentObjectType.Picture) 
     { 
      DocPicture picture = docObj as DocPicture; 
      if (picture.Title == "logo") // <--- I don't know how to set title in Word 
      { 
       //Replace the image 
       picture.LoadImage(Image.FromFile("logo.png")); 
      } 
     } 
    } 
} 
document.SaveToFile("generated.docx"); 
document.Close(); 

答えて

1

右あなたの写真をクリックしてください - > [図の書式設定] - > [レイアウト&のプロパティ] - > [ALTテキストを、あなたは(私はオフィス2013を使用しています)写真の下を参照、タイトル部分を見つけます。 enter image description here

+0

ありがとうございます!それがまさに私が探しているものです。私は試してすべてが動作します。 – Quan

関連する問題