C#读取Word文件示例代码_第1页
C#读取Word文件示例代码_第2页
C#读取Word文件示例代码_第3页
C#读取Word文件示例代码_第4页
C#读取Word文件示例代码_第5页
免费预览已结束,剩余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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论