手机
当前位置:查字典教程网 >编程开发 >C#教程 >C#获取Word文档中所有表格的实现代码分享
C#获取Word文档中所有表格的实现代码分享
摘要:今天从数据库生成了一份数据字典,但是没有备注,所以需要程序把表格都读出来。用到了下面的代码,亲测可用~~objectoFileName=@"...

今天从数据库生成了一份数据字典,但是没有备注,所以需要程序把表格都读出来。用到了下面的代码,亲测可用~~

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

【C#获取Word文档中所有表格的实现代码分享】相关文章:

在C#中调用VBScript、javascript等脚本的实现代码

C#反射在实际应用中的实例代码

解析C#彩色图像灰度化算法的实现代码详解

C#几种获取网页源文件代码的实例

C#解析json文件的实现代码

C# 实现简单打印的实例代码

分享C#操作内存读写方法的主要实现代码

将数组中指定数量的元素移动数组后面的实现代码

C#中让控件全屏显示的实现代码(WinForm)

解析c#显示友好时间的实现代码

精品推荐
分类导航