using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Word = Microsoft.Office.Interop.Word; namespace ChangeWord
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.killAllProcess();
            this.Change();
        }        /// <summary>
        /// 打开Word文件读取表格
        /// </summary>
        private void Change()
        {
            object fileName = "D:\\242021_2003631310153陈祥文.doc";
            object readOnly = true;
            object isVisible = true;
            object missing = System.Reflection.Missing.Value;
            //开启应用程序WINWORD.EXE
            //Word.ApplicationClass oWordApp = new Word.ApplicationClass();
            Word._Application oWordApp = new Word.Application();
            Word._Document oDoc = oWordApp.Documents.Open(ref fileName, ref missing, ref readOnly,
            ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
            ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing);            oDoc.Activate();            //循环取出表格
            for (int tablePos = 1; tablePos <= oDoc.Tables.Count; tablePos++)
            {
                Word.Table nowTable = oDoc.Tables[tablePos];
                 string tableMessage = string.Format("第{0}/{1}个表:\n", tablePos, oDoc.Tables.Count);                 for (int rowPos = 1; rowPos <= nowTable.Rows.Count; rowPos++)
                 {
                     for (int columPos = 1; columPos <= nowTable.Columns.Count; columPos++)
                     {
                         tableMessage += nowTable.Cell(rowPos, columPos).Range.Text;
                         tableMessage = tableMessage.Remove(tableMessage.Length - 2, 2);//remove \r\a
                         tableMessage += "\t";
                     }
                     tableMessage += "\n";
                 }
                 this.lbltableMessage.Text = tableMessage;
            }             
                                    
            //关闭
            //object doNotSaveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;
            //oDoc.Close(ref doNotSaveChanges, ref missing, ref missing);            this.killAllProcess();
            
         }        /// <summary>
        /// 关闭所有winword.exe进程 
        /// </summary>
        protected void killAllProcess()
        {
            System.Diagnostics.Process[] myPs;
            myPs = System.Diagnostics.Process.GetProcesses();
            foreach (System.Diagnostics.Process p in myPs)
            {
                if (p.Id != 0)
                {
                    string myS = "WINWORD.EXE" + p.ProcessName + " ID:" + p.Id.ToString();
                    try
                    {
                        if (p.Modules != null)
                            if (p.Modules.Count > 0)
                            {
                                System.Diagnostics.ProcessModule pm = p.Modules[0];
                                myS += "\n Modules[0].FileName:" + pm.FileName;
                                myS += "\n Modules[0].ModuleName:" + pm.ModuleName;
                                myS += "\n Modules[0].FileVersionInfo:\n" + pm.FileVersionInfo.ToString();
                                if (pm.ModuleName.ToLower() == "winword.exe")
                                    p.Kill();
                            }
                    }
                    catch
                    { }
                    finally
                    {
                    }
                }
            }
        }       }
}  主要是这句话,
if(oDoc.Tables.Count > 0)
大于0就是有表格,对话框自己写一个就行了