C#獲取Word文檔中所有表格的實現(xiàn)代碼分享
更新時間:2014年09月06日 08:36:50 投稿:junjie
這篇文章主要介紹了C#獲取Word文檔中所有表格的實現(xiàn)代碼分享,小編親測可用,需要的朋友可以參考下
今天從數(shù)據(jù)庫生成了一份數(shù)據(jù)字典,但是沒有備注,所以需要程序把表格都讀出來。用到了下面的代碼,親測可用~~
object oFileName = @"F:\數(shù)據(jù)庫.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}個表:\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# Windows API應用之基于GetDesktopWindow獲得桌面所有窗口句柄的方法
這篇文章主要介紹了C# Windows API應用之基于GetDesktopWindow獲得桌面所有窗口句柄的方法,結合實例形式分析了GetDesktopWindow函數(shù)用于獲取窗口句柄的具體使用方法與相關注意事項,需要的朋友可以參考下2016-08-08
C#實現(xiàn)Excel動態(tài)生成PivotTable
這篇文章主要為大家詳細介紹了C#實現(xiàn)Excel動態(tài)生成PivotTable的相關方法,感興趣的小伙伴們可以參考一下2016-04-04
c#中WinForm使用OpencvSharp4實現(xiàn)簡易抓邊
本文主要介紹了c#中WinForm使用OpencvSharp4實現(xiàn)簡易抓邊,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-05-05

