Read word by word from Msword document asp.net
I am working on an application in which I need to read word by word from uploaded document.
For this I have added the following code:
Microsoft.Office.Interop.Word.ApplicationClass Application =
new Microsoft.Office.Interop.Word.ApplicationClass();
object nullobj = System.Reflection.Missing.Value;
ob开发者_如何转开发ject file = "c:\\word.doc";
object value = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Document doc =
Application.Documents.Open(ref file,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj,
ref value,
ref value,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj);
doc.Activate();
//var ss = doc.Words[0];
var x = doc.Words;
foreach (var v in doc.Words)
{
}
string Doc_Content = doc.Content.Text;
// txtContent.Text = Doc_Content;
doc.Close(ref nullobj, ref nullobj, ref nullobj);
The loop is going on each word in the document but I am not able to get the word inside the loop. If someone has solution then please help me.
For this which namespace we have to required added
Microsoft.Office.Interop.Word.ApplicationClass Application =
new Microsoft.Office.Interop.Word.ApplicationClass();
You can cast V to range, and grab the text from it.
string ActualText = ((Range)v).Text;
精彩评论