使用Word API打开Word文档
2013-03-23 11:55
281 查看
使用Word API(非Openxml)打开Word文档简单示例(必须安装Word)
首先需要引入参照Microsoft.Office.Interop.Word
代码示例
注意:
该方法必须安装Word,运行速度可能比较慢。
如只是要取得Word里面的数据,且速度要求比较高,推荐使用Openxml,而且不需要安装Word。
首先需要引入参照Microsoft.Office.Interop.Word
代码示例
public void OpenWord() { // Word应用对象 Word.Application wdApp = null; // Word文档对象 Word.Document wdDoc = null; // Word路径 object oWdPath = "XXXXXXXXXXXXXX"; // Word设定:缺损项 object oMissing = System.Reflection.Missing.Value; // Word设定:不保存 object doNotSaveChanges = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges; try { // 新建Word应用 wdApp = new Word.Application(); // 设置Word应用为可见 wdApp.Visible = true; // 打开Word文档 wdDoc = wdApp.Documents.Open(ref oWdPath, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); } finally { #pragma warning disable // 关闭Word文档 if (wdDoc != null) { wdDoc.Close(); wdDoc = null; } // 关闭Word应用 if (wdApp != null) { wdApp.Quit(ref doNotSaveChanges, ref oMissing, ref oMissing); wdApp = null; } #pragma warning disable GC.Collect(); } }
注意:
该方法必须安装Word,运行速度可能比较慢。
如只是要取得Word里面的数据,且速度要求比较高,推荐使用Openxml,而且不需要安装Word。
相关文章推荐
- 使用Word API打开Word文档 ASP.NET编程中常用到的27个函数集
- 使用自动化打开并打印WORD文档
- C++/Qt中调用函数ShellExecute()打开图片或者word文档的使用方法
- 使用 Word 2007 以从右向左书写文档,在Word 2002 或 Word 2000 中打开顺序颠倒
- 设置word打开文档时默认使用“文档结构图”视图
- 使用WPS打开的word文档内容复制不到excel里
- 使用自动化打开并打印WORD文档
- 使用自动化打开并打印WORD文档
- 如何使用Java程序打开一个Word文档?
- 在 Word 2002 和 Word 2003 中如何使用“打开并修复”功能打开文档
- 单文档程序使用命令行参数方式打开
- python 直接打开word文档
- java 使用Java生成word文档
- PHP打开word文档
- 在iphone程序中打开word、execl、pdf等文档
- 如何使用 WebBrowser 控件在 Visual C# 2005 或 Visual C# .NET 中打开 Office 文档
- 在linux中使用php将word文档转为pdf
- JAVA不使用POI给Word文档添加水印
- 使用点聚 weboffice 以及vsto、 web service 实现word 的自动化文档处理
- java使用poi解析2007以上的word文档中的表格与图片