- 浏览: 4424392 次
- 性别:
- 来自: 湛江
博客专栏
-
SQLite源码剖析
浏览量:80266
-
WIN32汇编语言学习应用...
浏览量:70672
-
神奇的perl
浏览量:103860
-
lucene等搜索引擎解析...
浏览量:287095
-
深入lucene3.5源码...
浏览量:15097
-
VB.NET并行与分布式编...
浏览量:68142
-
silverlight 5...
浏览量:32432
-
算法下午茶系列
浏览量:46194
文章分类
最新评论
-
yoyo837:
counters15 写道目前只支持IE吗?插件的东西是跨浏览 ...
Silverlight 5 轻松开启绚丽的网页3D世界 -
shuiyunbing:
直接在前台导出方式:excel中的单元格样式怎么处理,比如某行 ...
Flex导出Excel -
di1984HIT:
写的很好~
lucene入门-索引网页 -
rjguanwen:
在win7 64位操作系统下,pygtk的Entry无法输入怎 ...
pygtk-entry -
ldl_xz:
http://www.9958.pw/post/php_exc ...
PHPExcel常用方法汇总(转载)
use warnings;
use strict;
use Win32::OLE;
my $word = CreateObject Win32::OLE 'Word.Application' or die $!;
$word->{'Visible'} = 1;
my $document = $word->Documents->Add;
my $selection = $word->Selection;
$selection -> TypeText("大家好");
$selection -> TypeParagraph;
$selection -> TypeText("How do you feel today");
$selection -> TypeParagraph;
$document->saveas('D:\深未来\测试\xxxxx.doc') ;
$word->quit();
具体说明:
Applies to: 2007 Microsoft Office System, Microsoft Office Word 2007
Joel Krist, Akona Systems
April 2007
<!---->
<!--src=[..\local\97421a3c-b771-4007-988f-496df6b850d3.gif]--> The 2007 Microsoft Office Add-in: Microsoft Save as PDF and 2007 Microsoft Office Add-in: Microsoft Save as XPS allow a Microsoft Office Word 2007 to export and save documents in the PDF and XPS formats. This article illustrates how to use the Microsoft Word 12.0 Object Library to access the Word 2007 Document.ExportAsFixedFormat method to programmatically convert an existing Word 2007 document to either the PDF format or the XPS format. <!--src=[..\local\ea6729f8-0f4e-41ff-bbec-a743cfa2929c.gif]-->To illustrate how to programmatically save a Word 2007 document to either the PDF format or the XPS format, this section walks through five key steps. To programmatically save a Word 2007 document to either the PDF format or the XPS format
1. Add a Reference to the Word 12.0 Object Library First, add a reference to the Microsoft Word 12.0 Object Library to the Visual Studio project. To do this, right-click the project in the Visual Studio Solution Explorer and select the Add Reference… menu item. Select the COM tab in the Add Reference dialog box, then scroll down to the Microsoft Word 12.0 Object Library component, select it, and then click OK to add the reference. Figure 1. Adding a Reference <!--src=[..\local\ea56098a-41b8-461f-8970-0c0def5c26dc.gif]-->2. Import the Word Interop Namespace Next, import the Microsoft.Office.Interop.Word namespace. This allows objects that are defined in that namespace to be referred to without having to specify the fully qualified namespace path. To import the namespace, add the following line to the top of the source file. Visual Basic
Imports Microsoft.Office.Interop.Word
C#
using Microsoft.Office.Interop.Word;
For Microsoft Visual Basic projects, you can also import the namespace by right-clicking the project in the Visual Studio Solution Explorer and selecting the Properties menu item. On the project properties page, select the References tab and then select the check box next to the Microsoft.Office.Interop.Word entry in the list of imported namespaces. 3. Create an Instance of the Word ApplicationClass Object To work with the Word 2007 object model, create an instance of the Word 2007 top-level ApplicationClass object and declare a variable to hold the reference to the document. Visual Basic
Dim wordApplication As ApplicationClass = New ApplicationClass() Dim wordDocument As Document = Nothing C#
ApplicationClass wordApplication = new ApplicationClass(); Document wordDocument = null; 4. Declare Appropriate Variables The following code blocks declare variables that help to make the parameters that are passed to methods used in the conversion code easier to read. The following variables are used with the Documents.Open method and ApplicationClass.Quit method. Use the Use the Visual Basic
Dim paramSourceDocPath As String = "C:\Temp\Test.docx" C#
object paramSourceDocPath = @"C:\Temp\Test.docx";
object paramMissing = Type.Missing;
The following variables are used with the Document.ExportAsFixedFormat method. The Visual Basic
Dim paramExportFilePath As String = "C:\Temp\Test.xps" Dim paramExportFormat As WdExportFormat = _ WdExportFormat.wdExportFormatXPS Dim paramOpenAfterExport As Boolean = False Dim paramExportOptimizeFor As WdExportOptimizeFor = _ WdExportOptimizeFor.wdExportOptimizeForPrint Dim paramExportRange As WdExportRange = _ WdExportRange.wdExportAllDocument Dim paramStartPage As Int32 = 0 Dim paramEndPage As Int32 = 0 Dim paramExportItem As WdExportItem = _ WdExportItem.wdExportDocumentContent Dim paramIncludeDocProps As Boolean = True Dim paramKeepIRM As Boolean = True Dim paramCreateBookmarks As WdExportCreateBookmarks = _ WdExportCreateBookmarks.wdExportCreateWordBookmarks Dim paramDocStructureTags As Boolean = True Dim paramBitmapMissingFonts As Boolean = True Dim paramUseISO19005_1 As Boolean = False C#
string paramExportFilePath = @"C:\Temp\Test.xps"; WdExportFormat paramExportFormat = WdExportFormat.wdExportFormatXPS; bool paramOpenAfterExport = false; WdExportOptimizeFor paramExportOptimizeFor = WdExportOptimizeFor.wdExportOptimizeForPrint; WdExportRange paramExportRange = WdExportRange.wdExportAllDocument; int paramStartPage = 0; int paramEndPage = 0; WdExportItem paramExportItem = WdExportItem.wdExportDocumentContent; bool paramIncludeDocProps = true; bool paramKeepIRM = true; WdExportCreateBookmarks paramCreateBookmarks = WdExportCreateBookmarks.wdExportCreateWordBookmarks; bool paramDocStructureTags = true; bool paramBitmapMissingFonts = true; bool paramUseISO19005_1 = false; 5. Implement the Conversion Code Next add code that opens the source document, exports it to the specified format, and exits Word 2007. Making the call to the Document.ExportAsFixedFormat method throws an exception if the add-in for the format is not currently installed. To handle this situation, the conversion code is wrapped in a Try…Catch block. The code that exits Word 2007, which allows it to unload from memory, is located in a Finally block. The shutdown-related code closes the Word 2007 document, exits the Word 2007 application, releases references to the underlying Word 2007 COM objects, and makes calls to the .NET garbage collector. For more information about how to release COM objects when you use managed code, see Chapter 2: Basics of Office Interoperability (Part 2 of 3) from the book Microsoft .NET Development for Microsoft Office. Visual Basic
Try ' Open the source document. wordDocument = wordApplication.Documents.Open(paramSourceDocPath) ' Export it in the specified format. If Not wordDocument Is Nothing Then wordDocument.ExportAsFixedFormat(paramExportFilePath, _ paramExportFormat, paramOpenAfterExport, _ paramExportOptimizeFor, paramExportRange, paramStartPage, _ paramEndPage, paramExportItem, paramIncludeDocProps, _ paramKeepIRM, paramCreateBookmarks, _ paramDocStructureTags, paramBitmapMissingFonts, _ paramUseISO19005_1) End If Catch ex As Exception ' Respond to the error Finally ' Close and release the Document object. If Not wordDocument Is Nothing Then wordDocument.Close(False) wordDocument = Nothing End If ' Quit Word and release the ApplicationClass object. If Not wordApplication Is Nothing Then wordApplication.Quit() wordApplication = nothing End If GC.Collect() GC.WaitForPendingFinalizers() GC.Collect() GC.WaitForPendingFinalizers() End Try C#
try { // Open the source document. wordDocument = wordApplication.Documents.Open( ref paramSourceDocPath, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing); // Export it in the specified format. if (wordDocument != null) wordDocument.ExportAsFixedFormat(paramExportFilePath, paramExportFormat, paramOpenAfterExport, paramExportOptimizeFor, paramExportRange, paramStartPage, paramEndPage, paramExportItem, paramIncludeDocProps, paramKeepIRM, paramCreateBookmarks, paramDocStructureTags, paramBitmapMissingFonts, paramUseISO19005_1, ref paramMissing); } catch (Exception ex) { // Respond to the error } finally { // Close and release the Document object. if (wordDocument != null) { wordDocument.Close(ref paramMissing, ref paramMissing, ref paramMissing); wordDocument = null; } // Quit Word and release the ApplicationClass object. if (wordApplication != null) { wordApplication.Quit(ref paramMissing, ref paramMissing, ref paramMissing); wordApplication = null; } GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); } There are a number of scenarios in which you may want to develop a Microsoft Office business application that requires both dynamic and static views of the same document. In Word 2007 you can use the 2007 Microsoft Office Add-in: Microsoft Save as PDF and 2007 Microsoft Office Add-in: Microsoft Save as XPS to save a Word 2007 document as either a PDF document or an XPS document. The key object that is used to save a Word 2007 document in either the PDF format or the XPS format is the Document object. The Document object has a method called Document.ExportAsFixedFormat, which has a number of key parameters that it accepts to save the target document in the desired format. This article specifically explores how to use the Documents.Open method and Document.ExportAsFixedFormat method to programmatically save a Word 2007 document as either a PDF document or an XPS document. To programmatically save a Word 2007 document as either a PDF document or an XPS document
<!--src=[../local/note.gif]-->Note:
The preceding example code used the Type.Missing object to specify that an optional parameter was not provided and that the default parameter value should be used. To change the behavior to use something other than the default parameter types and values, specify the appropriate parameter types and values. For more information about the Documents.Open method and Document.ExportAsFixedFormat method and the parameters that they accept, see the Word 2007 Object Model Reference.<!---->
<!----> |
自动化 (以前称为 OLE 自动化) 是程序用来公开它们的对象的开发工具、 宏语言和其他支持自动化的程序功能。例如对于电子表格程序可能会使工作表、 图表、 单元格或区域的单元格,每个为不同类型的对象。字处理器可能会公开对象 (如应用程序、 文档、 段落、 句子、 一个书签或所选内容。
当一个程序支持自动化时可以使用 Visual Basic 应用程序的访问它公开的对象。为应用程序操作这些对象在 Visual Basic 中的,通过调用方法在对象上或通过获取并设置该对象的属性。
可以使用代码示例在这篇文章中来控制 Word 从 Microsoft Access 2000、 Microsoft Excel 2000、 Microsoft PowerPoint 2000、 Microsoft Visual Basic 应用程序,或来控制 Word 支持自动化的任何其他客户端。
入门 》
<script type="text/javascript"></script> 有 Word for Windows 自动执行的四个主要步骤:- 添加到 Microsoft Word 9.0 对象库 的引用。
- 将变量声明为一个 Word 对象类型 (应用程序、 文档,和 so on)。
- 分配给您在步骤 2 中声明该对象变量 CreateObject 函数返回该对象。
- 使用属性和方法的对象变量来使 Word 自动运行。
第 1 步: 添加到 Word 9.0 对象库的引用
<script type="text/javascript"></script> 若要将对使用 Microsoft Access 2000、 Microsoft PowerPoint 2000,或 Microsoft Excel 2000 中,Microsoft Word 9.0 对象库 的引用,请按照下列步骤操作:- 在 Microsoft Access、 PowerPoint,或 Excel 工具 菜单上的指向 宏,然后单击 Visual Basic 编辑器。
- 在 Visual Basic 编辑器中,在 工具 菜单上单击 引用。
- 在 可用引用 的列表,单击以选中 Microsoft Word 9.0 对象库 复选框。
添加在 Microsoft Word 9.0 对象库 的引用允许您访问 Microsoft Word 联机帮助和 Microsoft Word vba 的应用程序的常数、 属性和方法的程序。注意若要直接自动化 Word 对象类型所需的 Microsoft Word 9.0 对象库 的引用。
添加到 Microsoft Word 9.0 对象库 的引用称为早期绑定。
有关对象绑定的详细信息请参阅 Microsoft 知识库中下面的文章:
步骤 2: 声明对象变量
<script type="text/javascript"></script> 若要声明对象变量,您变量就像维度任何变量,在于您可以声明该对象时指定类型的维度。例如对于 Word.Application、 文档,和 段落 是单独的 Word 对象。下面的示例命令行声明为类型 Word.Application 的对象的变量 objWD:
Dim objWD as Word.Application
步骤 3: 设置变量
<script type="text/javascript"></script> 有两个 Visual Basic 函数,您可以使用"绑定"到 Word 的已声明的对象变量: CreateObject 和 GetObject。主要区别是 word 的 word 的 CreateObject 函数创建一个新的实例,并且 GetObject 函数使用现有,或已经正在运行实例。您还可以使用 GetObject 将您的对象变量绑定到特定的 Word 文档。下面的示例命令行将 objWD 变量绑定到 Word 使用 CreateObject 函数:
Dim objWD as Word.Application
Set objWD = CreateObject("Word.Application")
Dim objWdDoc As Word.Document
Set objWdDoc = GetObject("c:\my documents\doc1.doc")
有关帮助您使用 vba 的应用程序的详细信息请参阅 Microsoft 知识库中下面的文章:
步骤 4: 使用属性和方法,可自动进行 Word
<script type="text/javascript"></script> 您完成步骤 1 到步骤 3 您可以使用对象变量来使 Word 自动运行。下面的示例宏使用自动化创建 Word 对象、 创建新文档、 添加一些的文本和保存该文档。
Sub AutomateWord()
' Declare the variable.
Dim objWD As Word.Application
' Set the variable (runs new instance of Word.)
Set objWD = CreateObject("Word.Application")
' Add a new document.
objWD.Documents.Add
' Add some text.
objWD.Selection.TypeText "This is some text."
' Save the document.
objWD.ActiveDocument.SaveAs filename:="mydoc.doc"
' Quit Word.
objWD.Quit
' Clear the variable from memory.
Set objWD = Nothing
End Sub
Sub WordMacro()
Documents.Add
Selection.TypeText "This is some text"
ActiveDocument.SaveAs filename:="mydoc.doc"
Quit
End Sub
参考
特定于自动化 Word 使用 Visual Basic 应用程序的详细信息,请参阅以下资源。 Microsoft Office 开发人员 Web 站点http:...
<script type="text/javascript"></script>
Microsoft Office 开发人员 Web 站点
<script type="text/javascript"></script>http://msdn.microsoft.com/office (http://www.msdn.microsoft.com/office)新闻组
<script type="text/javascript"></script> 下面的对等新闻组是可以帮助您与其他用户的 Visual Basic 应用程序的交互:知识库
<script type="text/javascript"></script> 有关帮助您使用 vba 的应用程序的详细信息请参阅 Microsoft 知识库中下面的文章:办公室助理
<script type="text/javascript"></script> 有关自动化,在 Visual Basic 编辑器中的详细信息在 帮助 菜单上单击 Microsoft Visual Basic 帮助、 在 Office 助手或应答向导中,键入 Communicating 与其他应用程序,然后单击 搜索 以查看相关主题。
http://msdn.microsoft.com/en-us/library/default.aspx
大家可以在以上找到方法
发表评论
-
Firebug-firefox下的编辑JS的利器
2013-02-10 18:54 4710Firebug是一个Firefox插件,集HTML查看和编辑 ... -
15 个顶级 HTML5 游戏引擎
2013-02-10 12:30 54481) HTML5 Game Engine Constr ... -
perl-lwp笔记
2013-02-05 19:51 24212008-01-07 10:25 perl的LWP模块介绍 ... -
perl-opengl几何变换函数
2013-02-01 10:48 1787#!/usr/bin/perl -w use strict ... -
perl-opengl基本图形操作-缩放,二维旋转,二维平移
2013-02-01 09:08 3496#!/usr/bin/perl -w use strict ... -
perl-opengl-glutMotionFunc鼠标事件
2013-01-25 15:54 5172#!/usr/bin/perl -w use stric ... -
perl-opengl-鼠标事件与球体视角
2013-01-25 11:19 2405#!/usr/bin/perl -w use stric ... -
perl-opengl键盘事件与色彩
2013-01-25 09:29 2772#!/usr/bin/perl -w use st ... -
perl-opengl-鼠标事件
2013-01-24 22:43 2001#!/usr/bin/perl -w use s ... -
perl-opengl立方体
2013-01-24 17:44 1816#!/usr/bin/perl -w use strict ... -
perl-opengl画距形
2013-01-24 17:01 1680#!/usr/bin/perl -w use stric ... -
用 X3D 替代 VRML 2.0 的十个理由
2013-01-24 15:24 1563用 X3D 替代 VRML 2.0 的十 ... -
perl-opengl椭圆算法
2013-01-23 17:31 1959#!/usr/bin/perl -w use strict ... -
使用cpan安装Perl模块时自动安装依赖模块的方法
2013-01-23 10:44 3507Comprehensive Perl Archive Net ... -
perl-opengl-直线绘制
2013-01-23 10:43 1511#!/usr/bin/perl -w use strict ... -
perl-opengl指定矩阵-坐标视图
2013-01-22 15:23 1712这两个都是glMatrixMode()函数的参数,那就先说 ... -
perl-opengl多边形近似球体
2013-01-21 21:18 2672#!/usr/bin/perl -w use stric ... -
perl-opengl学习-绘制点
2013-01-21 17:33 1698#!/usr/bin/perl -w use strict ... -
perl-opengl示例程序
2013-01-21 16:22 3275#!/usr/bin/perl -w use strict ... -
开源 Lisp 相关项目
2013-01-19 22:38 3942IOLib 项目 (http://common-lisp.n ...
相关推荐
【标题】"Go-go-ole-golang的Win32OLE实现"主要涉及到的是在Go语言中如何使用`go-ole`库来实现Windows操作系统上的Win32对象链接与嵌入(OLE)技术。OLE是微软在Windows平台上实现的一个组件对象模型(COM),它允许...
WINDOWS程序员使用指南(三)----OLE_DDEWINDOWS程序员使用指南(三)----OLE_DDE
Microsoft OLE DB Provider for ODBC (MSDASQL) 一项允许在 OLEDB 和 ADO(它在内部使用 OLEDB)上构建的应用程序通过 ODBC 驱动程序访问数据源的技术。 MSDASQL 是用于连接到 ODBC(而不是数据库)的 OLEDB 访问...
学习和熟练掌握OLE-DDE技术对于提升Windows应用程序的交互性和集成性至关重要。随着技术的发展,虽然现在更多地使用COM和后续的.NET框架,但对OLE-DDE的理解仍然是理解Windows编程历史和现代技术的基础。通过深入...
本程序利用C#2008版本,结合OLEDB技术,实现了对数据库的高效操作,包括对表的查询、插入和删除等基本功能。下面我们将深入探讨这些知识点。 **一、OLEDB简介** OLEDB(Object Linking and Embedding, Database)是...
OLEDB驱动程序的工作原理是通过实现OLEDB接口,提供一套标准的方法和属性,使得任何支持OLEDB的应用程序都能够理解并操作数据。对于MySQL-OleDB-Provider,它实现了这些接口,使得.NET或其他支持OLEDB的程序能够执行...
PI-OLEDB 提供了标准的 OLE DB(Object Linking and Embedding, Database)接口,使得开发人员能够通过多种编程语言(如 C++, VB.NET, C# 等)轻松地连接到 PI Server,进行数据读取、写入、更新和删除操作。...
my $excel = Win32::OLE->new('Excel.Application', 'Quit'); ``` 2. **打开或创建工作簿**:通过Excel实例打开现有工作簿或者创建新的工作簿。 ```perl my $workbook = $excel->Workbooks->Open('path_to_your_file...
OLEDB Provider则为这个系统提供了一条与.NET Framework、VB6、VC++等开发环境兼容的数据访问路径,使得开发者无需了解PostgreSQL的底层细节,即可通过标准的OLEDB接口进行数据操作。 首先,我们需要了解OLEDB ...
本主题主要探讨如何使用C++Builder通过OLE技术来操作Microsoft Word和Excel。C++Builder是一个集成开发环境(IDE),它提供了丰富的工具和类库,支持创建Windows应用程序,包括与Office套件的交互。 在C++Builder中...
在BCB中,通过调用OLE,读写WORD文件。
去OLE 使用共享库而不是cgo为Windows COM进行绑定。 松本康弘。 安装 要试验go-ole,您可以编译并运行示例程序: go get github.com/go-ole/go-ole cd /path/to/go-ole/ go test cd /path/to/go-ole/example/...
### VC平台下基于OLE的Word自动化操作应用 #### 引言 在众多工程项目中,将实验结果和数据呈现给用户是一项重要任务。然而,仅通过简单的文本形式展示这些信息往往不能满足用户的需求,特别是当需要生成复杂的表格...
在本案例中,"EXCEL.WORD操作类(OLE)"是一个利用OLE技术来操作Microsoft Word和Excel的C++类库。这个类库包含了对这两个办公软件的基本操作,如打开、显示、写入、读取和保存文件。 1. **OLE基础**:OLE最初是...
### VC控制WORD(OLE自动化) #### 一、引言 随着信息技术的发展,Word等办公软件在日常工作中的应用越来越广泛。为了提高工作效率,实现自动化办公的需求日益迫切。在Visual C++ (VC)环境下,通过OLE(Object ...
在处理复杂的数据结构时,如Word文档或其他OLE对象,创建和销毁OLE对象可能会消耗大量的系统资源。为了避免频繁创建和销毁OLE对象带来的性能开销,可以采用以下策略: - **重用现有对象**:尽可能复用已有的OLE对象...
OLEDB(Object Linking and Embedding, Database)是微软提出的一种数据访问接口,它允许应用程序通过统一的方式访问各种数据源,包括数据库、文件系统、Web服务等。在本主题中,我们将深入探讨“OLEDB驱动程序大全...
OLE的主要目的是实现跨应用的数据共享和交互,使VB应用程序能直接操作这些外部对象,从而增强功能和用户体验。 在VB中使用OLE,首先需要了解OLE控件。OLE控件是VB工具箱中的一种,它充当一个容器,用于在VB界面中...
OleView OLE/COM OLE/COM对象浏览器