无法在 microsoft.office.interop.word 中的当前图像后插入图像
Not able to insert image after the current one in word with microsoft.office.interop.word
我正在尝试打开一个现有的 word 文件并将图像插入其中(图像名称和路径被传递给函数)。
代码逻辑工作正常,但挑战是每次新图像文件插入/放置在最后一个图像文件的顶部one.mean最新图像显示在 word 文件的第一页,其余图像是相应的。
但是我的 objective 是最老的一个 top.Or 你可以说第一个将进入第一个宫殿,然后是第二个,第三个.....
这是我的代码示例。
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);
}
我已经用 below.I 修改了代码,正在传递范围对象,这解决了我在 now.Still 时遇到的问题,正在寻找更好的解决方案(如果有的话)。
object o_CollapseEnd = WordC.WdCollapseDirection.wdCollapseEnd;
WordC.Range imgrng = aDoc.Content;
imgrng.Collapse(ref o_CollapseEnd);
imgrng.InlineShapes.AddPicture(imgFilename, Type.Missing, Type.Missing,imgrng);
我已使用此 word to PDF 代码将您在 word 文档中的所有图像转换为 PDF 文档。
也许你会发现它有用!!!
我正在尝试打开一个现有的 word 文件并将图像插入其中(图像名称和路径被传递给函数)。
代码逻辑工作正常,但挑战是每次新图像文件插入/放置在最后一个图像文件的顶部one.mean最新图像显示在 word 文件的第一页,其余图像是相应的。 但是我的 objective 是最老的一个 top.Or 你可以说第一个将进入第一个宫殿,然后是第二个,第三个.....
这是我的代码示例。
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);
}
我已经用 below.I 修改了代码,正在传递范围对象,这解决了我在 now.Still 时遇到的问题,正在寻找更好的解决方案(如果有的话)。
object o_CollapseEnd = WordC.WdCollapseDirection.wdCollapseEnd;
WordC.Range imgrng = aDoc.Content;
imgrng.Collapse(ref o_CollapseEnd);
imgrng.InlineShapes.AddPicture(imgFilename, Type.Missing, Type.Missing,imgrng);
我已使用此 word to PDF 代码将您在 word 文档中的所有图像转换为 PDF 文档。
也许你会发现它有用!!!