c# 将word内容放到Excel的一个单元格中

        /// <summary>
        /// 将一个word文档中的所有文本存放到excel的指定单元格内
        /// using Excel = Microsoft.Office.Interop.Excel;
        /// using Word = Microsoft.Office.Interop.Word;
        /// </summary>
        /// <param name="wordPath">word文档的路径</param>
        /// <param name="excelPath">excel文档的路径</param>
        /// <param name="row"></param>
        /// <param name="col"></param>
        public void WordCopy2Excel(string wordPath, string excelPath, int row, int col)
        {
            string pos = "" + (char)('A' + row - 1) + col;
            object oMissing = System.Reflection.Missing.Value;
            Word._Application oWord;
            Word._Document oDoc;
       //打开应用  oWord
= new Word.Application(); oWord.Visible = true; object fileName = wordPath;
        //打开文档 oDoc
= oWord.Documents.Open(ref fileName, 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, ref oMissing, ref oMissing);
        //选中整个document oDoc.ActiveWindow.Selection.WholeStory();
        //拷贝到剪切板 oDoc.ActiveWindow.Selection.Copy();
        //关掉document oDoc.Close();
        //关掉应用程序 oWord.Quit();
        //打开excel应用程序 Excel.Application app
= new Excel.Application(); string filename = excelPath; object optional = System.Reflection.Missing.Value;
        //打开一个excel文档 Excel.Workbook wb
= app.Workbooks.Open( filename, optional, optional, optional, optional, optional, optional, optional, optional, optional, optional, optional ); app.Visible = true;
        //选中当前活动的sheet Excel._Worksheet sheet
= (Excel.Worksheet)wb.ActiveSheet;
        //选择粘贴模式(具体的模式有多少种 我也不太清楚 另外一种xlPasteFormats)还可以默认,但是是图片格式粘贴 sheet.Range[pos].PasteSpecial(Excel.XlPasteType.xlPasteValues); wb.Save(); app.Quit(); }

想提升速度,就是不要关app,将app.Quit()去掉

需要配置com组件,具体配置http://www.cnblogs.com/mengxingxinqing/archive/2013/06/07/3123344.html

获取word的所有文本内容

str = myWordDoc.Content.Text;

原文地址:https://www.cnblogs.com/mengxingxinqing/p/3121544.html