问题:
场景再现:将word复制到另一个文档,且该文档为含书签的项目,书签在复制时候会遇到,当含横向和纵向copy时,如用下面方式copy会存在书签丢失的问题。
此复制word方法由于按照节去copy存在如果书签跨两节,丢失问题
//1.创建新doc
Word.Application newapp = new Word.Application();
Word.Document newdoc;
object nothing = System.Reflection.Missing.Value;//用于作为函数的默认参数
newdoc = newapp.Documents.Add(ref nothing, ref nothing, ref nothing, refnothing);//生成一个word文档
//2.word可视化
newapp.Visible = true;
//3.复制旧doc
this.Select();
//4.黏贴到新doc
Object saveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;
int SectionSize = this.Sections.Count;
for (int i = 1; i <= SectionSize; i++)
{
this.Sections[i].Range.Copy();
newdoc.Sections[i].Range.PasteAndFormat(Word.WdRecoveryType.wdPasteDefault);
}
解决处理方式:
缺点:处理速度没有前面方法快速
//1.创建新doc
Word.Application newapp = new Word.Application();
Word.Document newdoc;
object nothing = System.Reflection.Missing.Value;//用于作为函数的默认参数
newdoc = newapp.Documents.Add(ref nothing, ref nothing, ref nothing, refnothing);//生成一个word文档
//2.word可视化
newapp.Visible = true;
this.Application.Selection.WholeStory();
this.Application.Selection.Copy();
newdoc.Application.Selection.PasteAndFormat(Word.WdRecoveryType.wdPasteDefault);
本文介绍了一种复制Word文档的方法,确保即使在包含书签的文档中进行横向和纵向复制时也能完整保留书签信息。通过全文复制而非按节复制的方式避免了书签丢失的问题。
658

被折叠的 条评论
为什么被折叠?



