我正在尝试从800多个具有相同结构的word文件中收集信息。头条部分有一张桌子。我需要的是表格中的内容。该表有4行,但当我尝试获取行数时,它返回1.
Word.Application m_word =new Microsoft.Office.Interop.Word.Application();
Word.Document doc;
Object filename = treeList1.FocusedNode["SOPName"].ToString();
Object filefullname = treeList1.FocusedNode["FullPath"].ToString();
Object confirmConversions = Type.Missing;
Object readOnly = Type.Missing;
Object addToRecentFiles = Type.Missing;
Object passwordDocument = Type.Missing;
Object passwordTemplate = Type.Missing;
Object revert = Type.Missing;
Object writePasswordDocument = Type.Missing;
Object writePasswordTemplate = Type.Missing;
Object format = Type.Missing;
Object encoding = Type.Missing;
Object visible = Type.Missing;
Object openConflictDocument = Type.Missing;
Object openAndRepair = Type.Missing;
Object documentDirection = Type.Missing;
Object noEncodingDialog = Type.Missing;
doc= m_word.Documents.Open(ref filefullname,
ref confirmConversions, ref readOnly, ref addToRecentFiles,
ref passwordDocument, ref passwordTemplate, ref revert,
ref writePasswordDocument, ref writePasswordTemplate,
ref format, ref encoding, ref visible, ref openConflictDocument,
ref openAndRepair, ref documentDirection, ref noEncodingDialog
);
m_word.Visible =true;
string msg=string.Empty;
Word.Table InfoTable =
doc.Sections[1].Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Tables[1];
msg += string.Format("The table has {0} rows,{1} columns.\n", InfoTable.Rows.Count, InfoTable.Columns.Count);
for (int i = 1; i <= InfoTable.Rows.Count; i++)
for (int j = 1; j <= InfoTable.Columns.Count; j++)
msg += string.Format("{0},{1}:{2}\n", i, j, InfoTable.Cell(i, j).Range.Text);
MessageBox.Show(msg);
我的代码有什么问题吗?