最后添加子文件格式的Word文档

时间:2015-05-26 21:22:00

标签: c# ms-word office-interop

我处理一个读取Word文档并在其末尾添加一些图像的进程。我遇到的问题是文档以字母列表结尾,我附加的图像正在成为该列表的一部分。在添加图像之前,我似乎无法找到结束该列表的方法。

Microsoft.Office.Interop.Word.Application winword =
    new Microsoft.Office.Interop.Word.Application();
winword.Visible = false;
object missing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Document document = winword.Documents.Open(documentName);

object lastLine = Microsoft.Office.Interop.Word.WdGoToItem.wdGoToLine;
object lastDirection = Microsoft.Office.Interop.Word.WdGoToDirection.wdGoToLast;
document.Sections.Add(missing);
document.Sections[document.Sections.Count]
    .Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].LinkToPrevious = false;
document.Sections[document.Sections.Count]
    .Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Text = "";

winword.Selection.GoTo(ref lastLine, ref lastDirection, ref missing, ref missing);
winword.Selection.EndKey(WdUnits.wdStory, missing);

foreach(string image in images)
{
    document.Application.Selection.InlineShapes.AddPicture(image);
}

document.SaveAs2("finished.doc",
                  Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument97);
document.Close();
winword.Quit();

0 个答案:

没有答案