C#獲取Word文檔中所有表格的實(shí)現(xiàn)代碼分享
今天從數(shù)據(jù)庫(kù)生成了一份數(shù)據(jù)字典,但是沒有備注,所以需要程序把表格都讀出來(lái)。用到了下面的代碼,親測(cè)可用~~
object oFileName = @"F:\數(shù)據(jù)庫(kù).docx"; object oReadOnly = false ; object oMissing = System.Reflection.Missing.Value; Microsoft.Office.Interop.Word._Application oWord; Microsoft.Office.Interop.Word._Document oDoc; oWord = new Microsoft.Office.Interop.Word.Application(); oWord.Visible = false; oDoc = oWord.Documents.Open(ref oFileName, ref oMissing, ref oReadOnly, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); //MessageBox.Show(oDoc.Tables.Count.ToString()); for (int tablePos = 1; tablePos <= oDoc.Tables.Count; tablePos++) { Microsoft.Office.Interop.Word.Table nowTable = oDoc.Tables[tablePos]; string tableMessage = string.Format("第{0}/{1}個(gè)表:\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); tableMessage += "\t"; } tableMessage += "\n"; } MessageBox.Show(tableMessage); }
- C# WORD操作實(shí)現(xiàn)代碼
- C#實(shí)現(xiàn)通過模板自動(dòng)創(chuàng)建Word文檔的方法
- C# Word 類庫(kù)的深入理解
- asp.net(c#)下讀取word文檔的方法小結(jié)
- 比較全的一個(gè)C#操作word文檔示例
- 使用c#在word文檔中創(chuàng)建表格的方法詳解
- c#開發(fā)word批量轉(zhuǎn)pdf源碼分享
- C#采用OpenXml實(shí)現(xiàn)給word文檔添加文字
- C#采用OpenXml給word里面插入圖片
- 使用C#實(shí)現(xiàn)在word中插入頁(yè)眉頁(yè)腳的方法
- C#實(shí)現(xiàn)合并多個(gè)word文檔的方法
- C#操作word的方法示例
相關(guān)文章
C#調(diào)用SQL語(yǔ)句時(shí)乘號(hào)的用法
這篇文章主要介紹了C#調(diào)用SQL語(yǔ)句時(shí)乘號(hào)的用法,可避免因符號(hào)引起的程序錯(cuò)誤,是C#程序設(shè)計(jì)人員有必要掌握的,需要的朋友可以參考下2014-08-08

C# Windows API應(yīng)用之基于GetDesktopWindow獲得桌面所有窗口句柄的方法

C#實(shí)現(xiàn)Excel動(dòng)態(tài)生成PivotTable

c#實(shí)現(xiàn)簡(jiǎn)單控制臺(tái)udp異步通信程序示例

c#中WinForm使用OpencvSharp4實(shí)現(xiàn)簡(jiǎn)易抓邊

淺析C#數(shù)據(jù)類型轉(zhuǎn)換的幾種形式

利用C#實(shí)現(xiàn)獲取當(dāng)前設(shè)備硬件信息