




免费预览已结束,剩余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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 河南省驻马店市第十七中学2026届九年级化学第一学期期中调研试题含解析
- 高血压病人护理公开课
- 2026届十堰市重点中学英语九年级第一学期期末调研模拟试题含解析
- 心态培训课程员工培训
- 2026届安徽省宿州地区化学九上期中检测试题含解析
- 2026届安徽六安市叶集区三元中学九年级化学第一学期期中联考模拟试题含解析
- 陕西省西安市蓝田县2026届化学九年级第一学期期中监测模拟试题含解析
- 生产报表数据培训
- 新员工入职培训
- 2026届广东省广州市东环中学英语九上期末复习检测模拟试题含解析
- 人教版(2019)高中生物必修1《分子与细胞》期末复习知识点考点提纲
- 2《企业会计准则第9号-职工薪酬(2014年修订)》
- 2024年太原市小店区供热公司招聘笔试参考题库附带答案详解
- 中医培训课件:《放血疗法》
- join-in-六上-Unit3-Festivals-Part1市公开课一等奖省赛课微课金奖课
- 市政道路监理规划及市政道路监理大纲
- (高清版)DZT 0331-2020 地热资源评价方法及估算规程
- 防震减灾科普
- 酒店工程节能降耗培训展示
- 设备维保的预防性保养与维护策略
- 【经典阅读】四年级阅读训练-人物描写分析(知识梳理+例文解析)(有答案)
评论
0/150
提交评论