开发者

How to read a word document in asp.net c#

i'm just workin on a project in asp.net c# 3.5 windows application which requires to read word document. i want to know how to read the *.doc file c开发者_如何学编程haracter by character.... how can i do it?


Microsoft.Office.Interop.Word.Application WApp; Microsoft.Office.Interop.Word.Document Wdoc;

WApp = new Microsoft.Office.Interop.Word.Application();
//Opening Word file
Thread.Sleep(5312);
Wdoc = WApp.Documents.Open(@"C:\Users\Doc.doc");
object start = 0;
object end = Wdoc.Characters.Count;
Range rng = Wdoc.Range(ref start, ref end);


int wordCount = Wdoc.Words.Count;
// Display retrieved (incomplete) text
rng.TextRetrievalMode.IncludeHiddenText = false;
rng.TextRetrievalMode.IncludeFieldCodes = false;

// Find phrase in text string
string WTest;
string[] Title;
Title = new string[10];
Title[1] = "word1 ";
Title[2] = "word2 ";
Title[3] = "word3 ";
Title[4] = "word4 ";
Title[5] = "word5 ";
Title[6] = "word6 ";
Title[7] = "word7 ";
Title[8] = "word8 ";
Title[9] = "word9 ";
int icount = 1;
int n = 1;
int i=1;

while (icount <= wordCount)
{
    WTest = Wdoc.Words[icount].Text.ToString();

    foreach(string element in Title)
    {

        if (Title[i] == WTest)
        {
            Assert.IsTrue(true);
            icount++;
            i++;
            break;
        }
        else if (i == wordCount)
        {
            Assert.Fail("Doc has no Data");
            break;
        }
        else
        {
            icount++;


        }
        break;  
    }

    continue;
}
 Wdoc.Close(true);
 WApp.Quit();

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜