在 MS Word 中设置图像标题,以便 Spire .NET 识别(定位)图像以将其替换为新图像
Set Title for Image in MS Word in order for Spire .NET to identify (locate) the image to replace it with a new one
我想使用 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();
我想使用 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();