我嘗試將多個圖像插入到文檔中,這些替換屬於與替換段落不同的頁面。這似乎是我嘗試在MS Word中打開生成的文檔時出現修復彈出窗口的原因。 這是我用複製整個圖像的代碼: OpenXml - How to identify whether the paragraph extends to next page當段落爲新行時出現問題打開XML
的XML看起來像這樣(修復一個:
tbl.Drawing drawing = buildImage(doc.MainDocumentPart.GetIdOfPart(imagePart), heightEmus, widthEmus);
tbl.Paragraph paragraph1 = new tbl.Paragraph();
tbl.ParagraphProperties paragraphProperties1 = new tbl.ParagraphProperties();
KeepLines keepLines1 = new KeepLines();
paragraphProperties1.Append(keepLines1);
BookmarkStart bookmarkStart1 = new BookmarkStart() { Name = "_GoBack", Id = "0" };
tbl.Run run1 = new tbl.Run();
LastRenderedPageBreak lastRenderedPageBreak1 = new LastRenderedPageBreak();
run1.Append(lastRenderedPageBreak1);
run1.Append(drawing);
BookmarkEnd bookmarkEnd1 = new BookmarkEnd() { Id = "0" };
paragraph1.Append(paragraphProperties1);
paragraph1.Append(bookmarkStart1);
paragraph1.Append(run1);
paragraph1.Append(bookmarkEnd1);
paragraph.InsertAfterSelf(paragraph1);
我已經嘗試了幾種方法後,受到啓發,通過這個帖子左側損壞一個在右邊):
請不要添加LastRenderedPageBreak屬性。當文檔下一次打開時,Word將重新計算頁面佈局(換行和分頁符),而不管文檔上次保存並關閉時的位置。如果它不在那裏,Word將無關緊要... –
我還沒有添加它,還是一樣 –
嘗試使用[OpenXml生產力工具](https://www.microsoft.com/zh-CN/download/details .aspx?id = 30425) - 您可以將文檔加載到文檔中,然後點擊「驗證」按鈕來查找文件中無效的內容。 – petelids