【发布时间】:2015-05-29 21:41:20
【问题描述】:
我正在尝试打开一个现有的 word 文件并将图像插入其中(图像名称以及传递给函数的路径)。
代码逻辑工作正常,但挑战是每次插入新图像文件/放置在最后一个文件的顶部。意味着最新图像显示在 word 文件的第一页上,其余的都是相应的。 但我的目标是最古老的将在顶部。或者您可以说第一个将成为第一个宫殿,然后是第二个,第三个.....
这是我的代码示例。
using WordC = Microsoft.Office.Interop.Word;
public void insertImage(string docFileName, string imgFilename)
{
WordC.Application wordApp = new WordC.Application();
// create Word document object
WordC.Document aDoc = null;
object readOnly = false;
object isVisible = false;
wordApp.Visible = false;
// wordApp.DisplayAlerts = false;
aDoc = wordApp.Documents.Open(docFileName, Type.Missing, ref readOnly,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, ref isVisible, Type.Missing,
Type.Missing, Type.Missing, Type.Missing);
aDoc.Activate();
// WordC.Document doc = WordApp.Documents.Open(docFileName);
// now add the picture in active document reference
aDoc.InlineShapes.AddPicture(imgFilename, Type.Missing, Type.Missing, Type.Missing);
aDoc.Save();
aDoc.Close(Type.Missing, Type.Missing, Type.Missing);
wordApp.Quit(Type.Missing, Type.Missing, Type.Missing);
}
【问题讨论】:
标签: c# selenium-webdriver ms-word office-interop