使用 C# 将图像添加到段落的互操作

本文关键字:段落 互操作 添加 图像 使用 | 更新日期: 2023-09-27 18:30:46

我正在使用C#编写一个word文档,现在需要在当前段落中添加图像。

当前行将添加到文档的顶部

aDoc.InlineShapes.AddPicture(path);

但我需要在选定的段落上添加图像,如下所示:

Paragraph parag = doc.Content.Paragraphs.Add(ref missing);
parag >> InlineShapes.AddPicture(path, ref missing, ref missing, ref missing);

如何找到添加段落本身的方法?

使用 C# 将图像添加到段落的互操作

您希望将其添加到段落的Range

parag.Range.InlineShapes.AddPicture(path, ref missing, ref missing, ref missing);

是的,有将图像插入特定位置的方法。

object missing = System.Reflection.Missing.Value;
var docRange = document.Range();
docRange.Start = 3;//your expected index of the whole doc
Word.InlineShape i_shape = 
question_para.Range.InlineShapes.AddPicture(question.Q_image.url,ref 
missing,ref missing,docRange);