using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Interop.Word;

namespace ChuPiao.Common.Utils
{
    public class WordParse
    {
        //读取word文档内容
        public static string ReadWord(string fileName)
        {
            List<string> codes = new List<string>();
            Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();

            Document wordDoc;
            object filePath = fileName;
            String strContent = "";
            object oMissing = System.Reflection.Missing.Value;
            object trueObject = true;
            object doNotSaveChanges = WdSaveOptions.wdDoNotSaveChanges;

            wordDoc = wordApp.Documents.Open(ref filePath, ref oMissing, ref trueObject, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                       ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

            //取得word文档内容
            strContent = wordDoc.Content.Text;

            //关闭文档
            wordDoc.Close(ref doNotSaveChanges, ref oMissing, ref oMissing);
            wordApp.Quit(ref doNotSaveChanges, ref oMissing, ref oMissing);

            return strContent;
        }
    }
}
