C# 当上一页已满时,通过C在Word中创建新页

C# 当上一页已满时,通过C在Word中创建新页,c#,image,list,ms-word,C#,Image,List,Ms Word,我正在使用C创建一个word文档,该文档通过互操作引用包含一组图像。我已经成功地让程序从列表中依次插入图像,但是我的问题是,当图像到达页面末尾时,而不是创建一个新页面来包含超过第一页大小的图像,所有图像都会在页面底部相互堆叠 我在网上找到了关于如何在选定点创建新页面的帮助,但是这不会很好地工作,例如:如果我在3个图像后创建了一条新行,如果使用了3个高图像,我可能会出现相同的错误;如果使用了3个短图像,则浪费了页面的一半 是否有方法检测下一个图像何时不适合页面,创建新页面并将下一个图像插入该页面

我正在使用C创建一个word文档,该文档通过互操作引用包含一组图像。我已经成功地让程序从列表中依次插入图像,但是我的问题是,当图像到达页面末尾时,而不是创建一个新页面来包含超过第一页大小的图像,所有图像都会在页面底部相互堆叠

我在网上找到了关于如何在选定点创建新页面的帮助,但是这不会很好地工作,例如:如果我在3个图像后创建了一条新行,如果使用了3个高图像,我可能会出现相同的错误;如果使用了3个短图像,则浪费了页面的一半

是否有方法检测下一个图像何时不适合页面,创建新页面并将下一个图像插入该页面

这是我当前的代码:

    private void CreateDocument()
    {
        try
        {
            //Create an instance for word app
            Microsoft.Office.Interop.Word.Application winword = new Microsoft.Office.Interop.Word.Application();

            //Set status for word application is to be visible or not.
            winword.Visible = false;

            //Create a missing variable for missing value
            object missing = System.Reflection.Missing.Value;

            //Create a new document
            Microsoft.Office.Interop.Word.Document document = winword.Documents.Add(ref missing, ref missing, ref missing, ref missing);

            object start_ofdoc = "\\startofdoc";

            // Get a range at the start of the document.
            Microsoft.Office.Interop.Word.Range start_range = document.Bookmarks.get_Item(ref start_ofdoc).Range;

            for (int i = 0; i < chosenQuestions.Count; i++)
            {
                //Add a picture
                string picture_file = chosenQuestions[i];
                Microsoft.Office.Interop.Word.InlineShape inline_shape = start_range.InlineShapes.AddPicture(picture_file, ref missing, ref missing, ref missing);

                // Format the picture.
                Microsoft.Office.Interop.Word.Shape shape = inline_shape.ConvertToShape();

                // Wrap text around the picture's square.
                shape.WrapFormat.Type = Microsoft.Office.Interop.Word.WdWrapType.wdWrapSquare;

                // Align the picture on the upper middle.
                shape.Left = (float)Microsoft.Office.Interop.Word.WdShapePosition.wdShapeCenter;
            }

            //Save the document
            object filename = installLocation + @"\SavedPapers\Test Paper";
            document.SaveAs(ref filename);
            document.Close(ref missing, ref missing, ref missing);
            document = null;
            winword.Quit(ref missing, ref missing, ref missing);
            winword = null;
            MessageBox.Show("Document created successfully!");
        }

        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

你为什么叫ConvertToShape?您需要的是InlineShape。\n分页是内置的Word功能,不仅取决于内容,还取决于所选打印机和纸张大小。不要帮忙。