有谁遇到过类似的问题:
两个word文档之间进行copy、paste操作时出现以下错误:
此方法或属性无效,因为剪贴板是空的或无效的!
生成服务合同的时候,合同附件有一个服务内容描述,这是需要根据配置不同的产品服务内容都不一样。
从对应的字模板中读出内容显示在合同中。
生成服务合同我用的是Office的COM组件,从子模板中读内容到服务合同,我就用了复制方法。
Range.Copy();
object Nothing = System.Reflection.Missing.Value;
Word.Application attachApp = new Application();
object type = WdBreakType.wdSectionBreakContinuous;
Word.Document attachDoc = attachApp.Documents.Open(ref docFile, ref Nothing, ref Nothing, ref Nothing,
ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing,
ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
attachDoc.Select();
attachApp.Selection.WholeStory();
attachDoc.Sections[1].Range.Copy();
object attach_ServiceContent = "attach_ServiceContent";
doc.Bookmarks.get_Item(ref attach_ServiceContent).Range.InsertBreak(ref type);
doc.Bookmarks.get_Item(ref attach_ServiceContent).Range.PasteAndFormat(WdRecoveryType.wdPasteDefault);
attachApp.NormalTemplate.Saved = true;
object doNotSaveChanges = WdSaveOptions.wdDoNotSaveChanges;
attachDoc.Close(ref doNotSaveChanges, ref Nothing, ref Nothing);
attachApp.Quit(ref doNotSaveChanges, ref Nothing, ref Nothing);
但是现在不稳定,有时间能生成成功,有时候报错:此方法或属性无效,因为剪贴板是空的或无效的。
我在网上找资料,也没有查出什么结果,有人说是:由于执行上述动作时间不够导致。
如果能捕获这种错误,并进行延时直到它完成这个动作;则能解决这个问题;
但我不知如果才能捕获上述错误;并进行相应处理.
//IDataObject data=Clipboard.GetDataObject();
有些人说用以上的做法,得到剪贴板的内容。
这种做法取到的data为null根本不能达到效果,此时是因为word中的剪切板和系统剪切板并不一样
求助,怎么样得到 Word 剪贴板 的内容,然后判断 Word 剪贴板 是否为空,为空就延时5秒再复制一次。
幕布斯7119047
摇曳的蔷薇
幕布斯6054654
守候你守候我
侃侃尔雅