本文介绍了如何使用互操作复制word文档的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用密钥识别word文档的一部分,然后将其复制到另一个word文档中。我怎样才能通过C#.net实现它。
i尝试以下结果作为文本我需要它作为文件
和段落应该是我用一个关键词确认了
我尝试过:
I need to identity a part of word document with a key then in need to copy it into another word document. how can i achieve it through C#.net.
i tried the following it result as text i need it as document
and paragraph should be i identified with a key word
What I have tried:
public string ReadFileContent(string path, int paraGraphNum)
{
int i = 0;
StringBuilder sb = new StringBuilder();
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);
Microsoft.Office.Interop.Word.Paragraphs DocPar = doc.Paragraphs;
// Count number of paragraphs in the file
long parCount = DocPar.Count;
// Step through the paragraphs
while (i < parCount)
{
i++;
if (i == paraGraphNum)
{
sb.Append(DocPar[i].Range.Text);
break;
}
}
doc.Close(ref nullobj, ref nullobj, ref nullobj);
wordApp.Quit(ref nullobj, ref nullobj, ref nullobj);
return (sb.ToString());
}
}
推荐答案
这篇关于如何使用互操作复制word文档的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!