欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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);
}

相關文章

最新評論