C#获取Word文档中所有表格的实现代码分享
2018-10-12 13:59
1036 查看
今天从数据库生成了一份数据字典,但是没有备注,所以需要程序把表格都读出来。用到了下面的代码,亲测可用~~
object oFileName = @"F:\数据库.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); }
您可能感兴趣的文章:
相关文章推荐
- JavaScript打开word文档的实现代码(c#)
- 用C#操作office组件库实现word文档的创建及文字 表格 图片的插入
- 用C#实现动态生成Word文档,在Word文档中插入表格,并将读出的数据填入到表格中
- C#获取Word文档结构图 并且转成Datatable表格
- c#通过Word实现打印的代码(表格为例)
- 实现同时将一个word文档中的所有表格执行“自动调整——根据窗口调整表格”操作
- C#获取远程网页中的所有链接URL(网络蜘蛛实现原理)
- 在C#获取word文档的字数,并输出到excel
- C#获取远程网页中的所有链接URL(网络蜘蛛实现原理)
- [C#]用C#动态生成Word文档并将数据填入Word表格中
- C#实现上传WORD文档并另存为WEB页面
- C#打开WORD文档内容并显示(未完善表格图片等排版显示的处理)
- C#实现上传WORD文档并另存为WEB页面
- 用C#实现在Word文档中搜索文本
- 根据word模板生成word表格报表文档(C#)
- 转载:获取数据库中的所有表 (C#实现)
- 用C#实现在Word文档中搜索文本
- C#在Word文档指定位置处理表格
- [C#]用C#动态生成Word文档并将数据填入Word表格中