`
deepfuture
  • 浏览: 4424210 次
  • 性别: Icon_minigender_1
  • 来自: 湛江
博客专栏
073ec2a9-85b7-3ebf-a3bb-c6361e6c6f64
SQLite源码剖析
浏览量:80261
1591c4b8-62f1-3d3e-9551-25c77465da96
WIN32汇编语言学习应用...
浏览量:70671
F5390db6-59dd-338f-ba18-4e93943ff06a
神奇的perl
浏览量:103858
Dac44363-8a80-3836-99aa-f7b7780fa6e2
lucene等搜索引擎解析...
浏览量:287085
Ec49a563-4109-3c69-9c83-8f6d068ba113
深入lucene3.5源码...
浏览量:15097
9b99bfc2-19c2-3346-9100-7f8879c731ce
VB.NET并行与分布式编...
浏览量:68134
B1db2af3-06b3-35bb-ac08-59ff2d1324b4
silverlight 5...
浏览量:32432
4a56b548-ab3d-35af-a984-e0781d142c23
算法下午茶系列
浏览量:46193
社区版块
存档分类
最新评论

perrl-操作word和excel、其它文档

阅读更多

 

 

 

ommunicating with Other Applicatio...

Communicating with Other Applications

Word Developer Reference

 

In addition to working with Microsoft Office Word data, you may want your application to exchange data with other applications, such as Microsoft Excel, Microsoft PowerPoint, or Microsoft Access. You can communicate with other applications by using Automation (formerly OLE Automation) or dynamic data exchange (DDE).

Automating Word from another application

Automation allows you to return, edit, and export data by referencing another application's objects, properties, and methods. Application objects that can be referenced by another application are called Automation objects.

The first step toward making Microsoft Word available to another application for Automation is to make a reference to the Word Application object. In Microsoft Visual Basic, you use the Visual Basic CreateObject or GetObject function to return a reference to the Word Application object. For example, in a Microsoft Office Excel procedure, you could use the following instruction.

Set wrd = CreateObject("Word.Application")

This instruction makes the Application object in Word available for Automation. Using the objects, properties, and methods of the Word Application object, you can control Word. For example, the following instruction creates a new Word document.

wrd.Documents.Add

Use the Visible property to make the new document visible after creating it.

wrd.Visible = True

The CreateObject function starts a Word session that Automation will not close when the object variable that references the Application object expires. Setting the object reference to the Visual Basic Nothing keyword will not close Word. Instead, use the Quit method to close the Word application. The following Microsoft Excel example displays the Word startup path. The Quit method is used to close the new instance of Word after the startup path is displayed.

Set wrd = CreateObject("Word.Application")

MsgBox wrd.Options.DefaultFilePath(wdStartupPath)

wrd.Quit

Automating another application from Word

To exchange data with another application using Automation from Word, you first obtain a reference to the application using the CreateObject or GetObject function. Then, using the objects, properties, and methods of the other application, you add, change, or delete information. When you finish making your changes, close the application. The following Word example displays the Microsoft Excel startup path. You can use the Visual Basic Set statement with the Nothing keyword to clear an object variable, which has the same effect as closing the application.

Set myobject = CreateObject("Excel.Application")

MsgBox myobject.StartupPath

Set myobject = Nothing

Using dynamic data exchange (DDE)

If an application does not support Automation, DDE may be an alternative. DDE is a protocol that permits two applications to communicate by continuously and automatically exchanging data through a DDE "channel." To control a DDE conversation between two applications, you establish a channel, select a topic, request and send data, and then close the channel. The following table lists the tasks that Word performs with DDE and the methods used to control each task in Visual Basic.

Security  Dynamic data exchange (DDE) is an older technology that is not secure. If possible, use a more secure alternative to DDE, such as object linking and embedding (OLE).

Task

Method

Starting DDE

DDEInitiate

Getting text from another application

DDERequest

Sending text to another application

DDEPoke

Carrying out a command in another application

DDEExecute

Close DDE channel

DDETerminate

Close all DDE channels

DDETerminateAll

在Perl开发中,很可能会碰到一些不同格式的文件——XML、PDF、CSV及RSS文件等,和一些不同的二进制数据格式。Perl应用程序需要操作这些文件,对它们进行读写。

此时,可以求助于全面Perl档案网络(CPAN),简化文件操作工作。CPAN拥有数量庞大、用于处理不同文件格式的Perl模块。本文列出了10个这样的模块,开发人员可以使用它们对自定义文件格式进行操作。

注意:可以从网络直接安装CPAN,下面的链接提供了使用说明:

http://www.cpan.org/misc/cpan-faq.html#How_install_Perl_modules

表 A

包名
 描述
 
DBI
 此模块提供了不依赖数据库的包装,允许Perl与数据库进行通讯。它支持数据库连接和管理,支持执行查询、事务、存储程序和出错处理。通过添加数据库驱动程序,它能支持不同数据库,如:MySQL、 PostgreSQL 和Oracle等。

需要从RDBMS中得到数据时,使用此包。
 
Archive::Tar
 此模块通过一个简单的面向对象界面,对TAR档案文件进行读和写操作。它允许将多个文件打包到一个TAR文件、允许列出TAR文件的内容,并且支持选择性地从TAR文件中提取文件。它也可用于GZIP压缩文件。

需要创建TAR或GZ档案文件或从档案文件中提取文件时,使用此包。
 
Archive::Zip
 此模块用于Perl程序读写ZIP档案文件。它提供了OOP方法创建和读ZIP文件,并且支持向档案文件中添加新文件、更改档案文件的内容(包括更改名字和日期)、提取档案文件内容或查询文件信息。

需要创建ZIP文件或需要从ZIP档案文件中提取文件时,使用此模块。
 
Class::CSV
 此模块提供基于对象的构架,对逗号分隔的数据进行有效处理。它允许CSV文件作为对象出现(反之亦然),可以将逗号间隔的值读入Perl变量。它也包含了使用自定义模式和分隔符向文件中写入新CSV记录的方法。

需要操作逗号分隔的数据字段时,使用此模块。
 
Unix::PasswdFile
 此模块提供面向对象界面,操作不同类型的密码文件。它包含添加、编辑和删除用户和密码的方法,也包含验证密码和产生密码的方法。它也可用于密码

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics