0

我想使用 Spire .NET 替换模板中的图像并保存为输出 docx 文件。我使用下面的代码来替换它。我的问题是我不知道如何在 MS Word 中为图像设置图像标题,以便 Spire 知道要替换我的图像的位置。

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();
4

1 回答 1

1

右键单击您的图片-> 设置图片格式-> 布局和属性-> ALT TEXT,然后您会找到标题部分,见下图(我使用的是Office 2013)。 在此处输入图像描述

于 2017-07-12T02:52:18.837 回答