WordDoc中缺少一页

本文关键字:一页 WordDoc | 更新日期: 2023-09-27 18:15:12

我正在添加关于"图像"装入我的单词的图像,即所谓的InlineShapes。但是我有一个问题,8图像被创建,但只有7在word文件中"上传",为什么呢?

 int pagecount = document.PageCount;
 //With the int pagecount we can create as may screenshots as there are pages in the document
 for (int index = 1; index < pagecount; index++)
 {
     application.Selection.InlineShapes.AddPicture(outputFileName + index + ".jpg");
 }

是的,我的页数也是8。

foreach (Microsoft.Office.Interop.Word.InlineShape inline in doc.InlineShapes)
{
    //Special sacling is done  or landscape docs as  well as portrait doumcnets
    if (inline.Height < inline.Width)
    {
        doc.PageSetup.Orientation = WdOrientation.wdOrientLandscape;
        inline.ScaleWidth = 90;
        inline.ScaleHeight = 90;
    }
}

这是每个图像插入word文件时的缩放,这个循环只"激活"它自己七次,但为什么呢?

WordDoc中缺少一页

您的pageCount为8,但您正在从index 1迭代,直到它大于或等于pageCount

要解决这个问题,从index = 0 开始,直到index <= pagecount,从逻辑的角度来看,哪个有意义。所以:

for (int index = 0; index < pagecount; index++)

for (int index = 1; index <= pagecount; index++)