如何在c#中加载旧的word文件.doc

时间:2014-07-10 12:27:08

标签: c# office-interop .doc

使用Office 2010,我可以使用DocumentFormat.OpenXml轻松访问.docx文件。

但是,对于.doc,它失败了(文件有旧的winword格式)。

Microsoft.Office.Interop.Word.Application wordApp;
wordApp = new Microsoft.Office.Interop.Word.Application();
Object oFileName = fullFilePath;
object missing = System.Reflection.Missing.Value;
object oFormat = Microsoft.Office.Interop.Word.WdOpenFormat.wdOpenFormatDocument97;
object saveChange = false;
try {
    Microsoft.Office.Interop.Word.Document doc = 
        _wordApp.Documents.Open( ref oFileName, ref missing , ref missing ,
            ref missing , ref  missing , ref missing , ref missing ,
            ref missing , ref missing , ref oFormat, ref missing ,
            ref isVisible, ref missing , ref missing , ref missing , ref missing );

    textBuilder.Append( doc.Content.Text );

    wordApp.Documents.Close( ref saveChange, ref missing, ref missing );
    }
catch (Exception ex) {
    textBuilder.Append( "<ERROR>" + "\n" + ex.Message );
    }
finally {
    wordApp.Quit(ref saveChange, ref missing, ref missing );
    wordApp = null;
    }

使用&#39; WdOpenFormat&#39;的所有可能值,我总是异常(虚构&#34; concurent access&#34;)。

如何解决?

最好的问候。

0 个答案:

没有答案