




免费预览已结束,剩余1页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
C 读取读取Word文档示例代码文档示例代码 在Visual Studio 2005中新建控制台应用程序 命名为GetWordContent 添加如下引用 Microsoft Office Interop Word System Drawing System Windows Forms 详细代码如下 详细代码如下 using System using System Collections Generic using System Text using System IO namespace GetWordContent class Program STAThread static void Main string args 根 据Y需 要 a输 入 正y确 的 OA文 档 路 径 string fileName E ylq 2010 GetWordContent GetWordContent bin Debug OA文 档 doc bool isOpen OfficeDocIO OpenWord fileName Console WriteLine 打 开aWord文 档 0 是 否 成 功 o 1 Path GetFileName fileName isOpen Console WriteLine Console WriteLine 获 取 分 段 落 文 本 内 容 Y 段 落 索 引 y从 1开a始 o int paragraph OfficeDocIO getParCount Console WriteLine 共2有 D 0 段 paragraph 段 落 索 引 y从 1开a始 for int i 1 i paragraph i Console WriteLine 段 落 0 1 i OfficeDocIO ReadPar i Console WriteLine Console WriteLine 直 接 获 取 Word的 全 部 文 本 内 容 Y o Console WriteLine OfficeDocIO GetDocContent OfficeDocIO CloseWord Console ReadLine 操 作 Word的 接 口 帮 助 类 public class OfficeDocIO private static Microsoft Office Interop Word Application appWord null private static Microsoft Office Interop Word Document docWord null 打 开a一 个 Word文 档 相 对 的 方 法 是 CloseWord 文 件t名 public static bool OpenWord string file appWord new Microsoft Office Interop Word Application object path file object missing System Reflection Missing Value object readOnly true try docWord appWord Documents Open ref path ref missing ref readOnly ref missing ref missing ref missing ref missing ref missing ref missing ref missing ref missing ref missing ref missing ref missing ref missing ref missing return true catch Exception e Console WriteLine e Message appWord null return false 读 取 word文 档 的 第 i段 public static object ReadPar int i try string temp docWord Paragraphs i Range Text return temp catch Exception e Console WriteLine Error e ToString return null 返 回 word文 档 一 共2几 段 public static int getParCount return docWord Paragraphs Count 获 取 文 档 的 文 本 内 容 Y public static object GetDocContent return docWord Content Text 提 取 word文 档 中D表 格 的 内 容 Y 表 格 索 引 y 行D号 列 D号 内 容 Y类 型 1为a文 本 2为a图 片 提 取 出 来 的 内 容 Y public static object GetWordTableContent int tableid int rowIndex int colIndex int type if docWord null try switch type case 1 if docWord Tables tableid Rows Count rowIndex 1 break case 2 if docWord Tables tableid Rows Count rowIndex 1 appWord Selection Copy System Drawing Image image System Windows Forms Clipboard GetImage content image if image null content ish break default break return content catch Exception e Console WriteLine e Message return null 关 闭 打 开a的 word文 档 public static void CloseWord object missing System Reflection Missing Value try if docWord null docWord Close ref missing ref missing ref missing docWord null
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025至2030中国白银行业市场发展分析及发展趋势与投资前景报告
- 2025至2030中国男式化妆品行业市场发展现状及发展前景与投资风险报告
- 2025至2030中国甘蔗榨汁机械行业深度研究及发展前景投资评估分析
- 招聘培训课件素材
- 教育心理学在家庭环境中的实践-以培养孩子同理心为例的探索研究
- 教育科技伦理视角下的创新与责任
- 企业教育培训的科技伦理要求及实现途径
- 教育设施与节能环保的完美结合
- 智慧教室中的情绪识别与干预策略研究
- 抖音商户运营经理直播后复盘会议制度
- 2025年高考数学全国新课标Ⅱ卷试卷评析及备考策略(课件)
- 黑龙江司法警官职业学院2025年招生政治考察表
- 《铁路技术管理规程》(普速铁路部分)
- (正式版)CB∕T 4549-2024 船舶行业企业加油-驳油作业安全管理规定
- 校长竞聘试题
- 结构化面试评分表考官计分平衡表面试成绩汇总表
- LED显示屏合同范本
- 初中化学实验探究教学方法讲座
- 燃机发电机转子一点接地保护全部校验作业指导书
- 2019-2020学年广东省廉江市实验学校北师大版五年级下册期末复习数学试卷1
- 天龙自动打怪脚本
评论
0/150
提交评论