Csharp/C#教程:C#获取Word文档中所有表格的实现代码分享分享

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

objectoFileName=@"F:数据库.docx"; objectoReadOnly=false; objectoMissing=System.Reflection.Missing.Value; Microsoft.Office.Interop.Word._ApplicationoWord; Microsoft.Office.Interop.Word._DocumentoDoc; oWord=newMicrosoft.Office.Interop.Word.Application(); oWord.Visible=false; oDoc=oWord.Documents.Open(refoFileName,refoMissing,refoReadOnly,refoMissing,refoMissing, refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing); //MessageBox.Show(oDoc.Tables.Count.ToString()); for(inttablePos=1;tablePos<=oDoc.Tables.Count;tablePos++) { Microsoft.Office.Interop.Word.TablenowTable=oDoc.Tables[tablePos]; stringtableMessage=string.Format("第{0}/{1}个表:n",tablePos,oDoc.Tables.Count); for(introwPos=1;rowPos<=nowTable.Rows.Count;rowPos++) { for(intcolumPos=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#实现通过模板自动创建Word文档的方法C#Word类库的深入理解asp.net(c#)下读取word文档的方法小结比较全的一个C#操作word文档示例使用c#在word文档中创建表格的方法详解c#开发word批量转pdf源码分享C#采用OpenXml实现给word文档添加文字C#采用OpenXml给word里面插入图片使用C#实现在word中插入页眉页脚的方法C#实现合并多个word文档的方法C#操作word的方法示例

标签: 表格

C++标准模板库map的常用操作

C#百万数据查询出现超时问题的解决方法

上述就是C#学习教程:C#获取Word文档中所有表格的实现代码分享分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请点击右边联系管理员删除。

如若转载,请注明出处:https://www.ctvol.com/cdevelopment/907229.html

(0)
上一篇 2021年10月24日
下一篇 2021年10月24日

精彩推荐