将内容从一个.docx文件复制到另一个.docx文件 [英] copy content from one .docx file to another .docx file
本文介绍了将内容从一个.docx文件复制到另一个.docx文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我能够从word文件中读取已损坏的内容并将其恢复但是我仍然坚持如何复制内容以创建新的word文件并将该内容复制到其中
这里是bel; ow代码来阅读内容,但是请帮助我创建一个新单词并复制contetnt而不会丢失确切的内容格式。
i''m able to read the content from word file which is corrupted and recovery it but im stuck how to copy the content to create a new word file and copy that content to it
here is the bel;ow code to read the content , but please help me to create a new word and copy contetnt without loosing the exact formats of content.
Microsoft.Office.Interop.Word.ApplicationClass wordApp = new ApplicationClass();
object file = path;
object nullobj = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open(
ref file, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,true);
doc.ActiveWindow.Selection.WholeStory();
IDataObject data = Clipboard.GetDataObject();
txtFileContent.Text = data.GetData(DataFormats.Text).ToString();
doc.Close(ref nullobj, ref nullobj, ref nullobj);
wordApp.Quit(ref nullobj, ref nullobj, ref nullobj);
推荐答案
因为我的senario就像我有一个损坏的.docx文件,我可以'打开它并阅读它,所以我要做的就是从中读取内容并复制该文件。
i得到解决方案,因为我没有不要复制但是恢复损坏的.docx文件并用另一个名字保存它。
as my senario is like i had a Corrupted .docx file , i can''t open it and read it,so what i have to do is read the content from it and make a duplicate of that file.
i got the solution as i didn''t copy but Recovered the Corrupted .docx file and saveas it with another name.
Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
object file = path;
object nullobj = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open(
ref file, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, true);
Object oSaveAsFile = (Object)"C:\\SampleDoc.docx";
doc.SaveAs2(oSaveAsFile, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatXMLDocument);
doc.Close(ref nullobj, ref nullobj, ref nullobj);
wordApp.Quit(ref nullobj, ref nullobj, ref nullobj);
这篇关于将内容从一个.docx文件复制到另一个.docx文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文