我是使用C#编程的新手,正在使用Microsoft.Office.Interop.Word扩展。我的程序接收多个Word文档,并将它们插入到单个文档中。在我的文档Picture showing my issue中重置编号方案时遇到问题
这是我用来插入文档的代码:
word.Selection.InsertNewPage();
Word.Paragraph para2;
para2 = doc.Content.Paragraphs.Add(ref missing);
para2.Range.Text = "Vertrag";
para2.Range.Font.Bold = 1;
para2.Range.Font.Size = 24;
para2.Range.Font.Name = "Arial";
para2.Format.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
para2.Range.InsertParagraphAfter();
//Resetting the Font to normal
word.Selection.GoTo(ref gotoPage, ref gotoLast, ref missing, ref missing);
word.Selection.ClearFormatting();
//ADDING THE FOURTH PAGE
word.Selection.InsertNewPage();
word.Selection.GoTo(ref gotoPage, ref gotoLast, ref missing, ref missing);
doc.Bookmarks.get_Item(ref endOfDoc).Range.InsertFile(filePathLeist, ref missing, ref oFalse, ref oFalse, ref oFalse);
word.Selection.GoTo(ref gotoPage, ref gotoLast, ref missing, ref missing);
//word.Selection.ClearFormatting();
//ADDING THE FIFTH PAGE
word.Selection.GoTo(ref gotoPage, ref gotoLast, ref missing, ref missing);
word.Selection.InsertNewPage();
string filePathAGB = filePathCommon + "\\effexx_WSIV_allgemein_AGB_2020_V1_0.docx";
doc.Bookmarks.get_Item(ref endOfDoc).Range.InsertFile(filePathAGB, ref missing, ref oFalse, ref oFalse, ref oFalse);我尝试清除两个文档之间的格式,但没有起作用。有人能告诉我我做错了什么吗?我该怎么做才能解决这个问题?
发布于 2020-08-31 22:48:18
这可能是在评论中做得更好,但我也是新来的,还不允许评论。
下面的页面虽然旧了,但应该是有帮助的:Methods for Restarting Numbering Using vba by Margaret Aldis, Word MVP
看着你的代码,它看起来很好,但Word中的自动编号是混乱的。这已经是超过25年的事实了。Word Numbering Explained by John McGhie, MVP有两个可靠的方法,它们几乎是牢不可破的。第一种方法是在段落样式上附加一个编号方案,每个级别对应一个编号方案,如Shauna的教程“How to create numbered headings or outline numbering in Word”中所述。如果您的文档中的编号与相同的样式相关联,则应该无缝集成。
第二种方法已经存在超过25年了,它是使用序列字段。其中一个运行得很好,但必须在每个文档中以相同的方式进行设置。
通过代码将多个文档中的文档编号修复为使用相同的方法超出了我的能力范围。任何试图这样做的人都需要知道编号是如何设置的,我想。玛格丽特·奥尔迪斯建议:“您可以创建列表模板,并使用VBA宏将每个级别链接到适当的样式。”如果我尝试这样做,我会创建一个具有这些样式的模板,然后使用OrganizerCopy method将样式传输到文档,并在文档中进行编号,将适当的样式应用于文档中各种编号的段落。然而,这可能会使这些段落的任何格式变得混乱。Using the Organizer in Word。可以从我的网站下载example of a template that can do this。
为便于将来进行此操作,您可能希望在Word中有一个文档模板,该模板用作必须合并的新文档的基础。此模板应设置编号方案,并应在每个文档中使用该方案。我推荐肖娜的方法。要使用它,您的用户应该使用适当的样式来应用编号,而不是“主页”选项卡上的按钮。
请注意,在讨论Word时,术语“模板”是一个术语、艺术或行话。不要把它理解为普通英语中的通常含义。Templates in Microsoft Word
如果使用序列字段,则可以将字段存储在AutoText或某种构建块中。这在我的page on numbering中有描述。
https://stackoverflow.com/questions/63671479
复制相似问题