0

I have to build an application in C#.NET with which i can search for certain words in a Word document. I've seen that there are API's for this in C#.NET. But i need to take this a step further.

One thing i want to be able to do is search with a regex string.

And another thing i need to do is search for a range of numbers. So i should be able to say something like >500. And it should then find every "word" that has a larger value than 500.

So the last two things are my problem. I couldn't find any direct info about this. Is it possible to search in a Word document using regex with C# code? And is there a good way to specify a range if numbers that it should find?

I want to do this in C#.NET.

Any info on this is appreciated!

4

1 に答える 1

0

私は.txtファイルでそれを行いました。コードの最初の行を変更し、Word ファイルを開く必要がありますが、次のようにする必要があります。

string fileData = System.IO.File.ReadAllText(@"C:\1\1.txt");  
        string[] words = fileData.Split(' ');  
        List<int> integers = new List<int>();  
        foreach (string word in words)  
        {  
            try  
            {  
                int integer = int.Parse(word);  
                if(integer > 500)  
                    integers.Add(integer);  
            }  
            catch (Exception)  
            {  
                //some code maybe 
            }  
        }  
        foreach (int integer in integers)  
        {  
            MessageBox.Show(integer.ToString());  
        }  

Word 文書を開く方法については、.docx ファイルの読み方を参照してください。

于 2012-08-22T07:46:41.237 に答える