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();
ありがとうございます!それがまさに私が探しているものです。私は試してすべてが動作します。 – Quan