Access Word Object Model thru C# to get at Paragraphs

If I do this process using VBA thru Word it takes about 10 seconds

If I run this code thru DotNet C# calling word it takes30 minutes to process
30,000 paragraphs. Is the way I am doing this in DotNet correct or is there a
faster way???

All I need to do is loop thru the paragraphs and do some task on the text depending on the

formatting or properties set on the Paragraph

Thanks

using

Microsoft.Office.Interop.Word;

public class WordDoc

{

ApplicationClass WordApp;

public WordDoc(string sFileName)
{
WordApp = new ApplicationClass();
WordApp.Visible = false;
FileName = sFileName;
}

public void Process()
{

object read_only = false;
object visible = true;
object ofalse = false;
object otrue = true;
object dynamic = 2;

object missing = System.Reflection.Missing.Value;
object oFileName = FileName;

Document Doc = WordApp.Documents.Open(ref oFileName, ref
missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref
missing, ref missing,
ref missing, ref missing, ref missing, ref
missing, ref missing);

for(int i = 1; i <= Doc.Paragraphs.Count; i++)
{
string sLine = Doc.Paragraphs(i).Range.Text;
…..
}

}

引文来源  Access Word Object Model thru C# to get at Paragraphs

 

=================================================================

遇到了同样的性能问题,同时发现内存一直不被释放,痛苦中……

 

看来Microsoft声明不支持Office的Server端自动处理,应该是有原因的。