惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tailwind CSS Blog
大猫的无限游戏
大猫的无限游戏
L
LINUX DO - 热门话题
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
雷峰网
雷峰网
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
V
V2EX
GbyAI
GbyAI
量子位
Microsoft Azure Blog
Microsoft Azure Blog
有赞技术团队
有赞技术团队
G
Google Developers Blog
云风的 BLOG
云风的 BLOG
B
Blog
Microsoft Security Blog
Microsoft Security Blog
S
SegmentFault 最新的问题
O
OpenAI News
N
News and Events Feed by Topic
博客园 - Franky
爱范儿
爱范儿
Forbes - Security
Forbes - Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V2EX - 技术
V2EX - 技术
Application and Cybersecurity Blog
Application and Cybersecurity Blog
N
News and Events Feed by Topic
N
News | PayPal Newsroom
Schneier on Security
Schneier on Security
Cloudbric
Cloudbric
Security Archives - TechRepublic
Security Archives - TechRepublic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Recent Commits to openclaw:main
Recent Commits to openclaw:main
人人都是产品经理
人人都是产品经理
P
Privacy International News Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog RSS Feed
阮一峰的网络日志
阮一峰的网络日志
D
DataBreaches.Net
Last Week in AI
Last Week in AI
罗磊的独立博客
Spread Privacy
Spread Privacy
Recent Announcements
Recent Announcements
The Cloudflare Blog
Google DeepMind News
Google DeepMind News
AWS News Blog
AWS News Blog
The Register - Security
The Register - Security
Y
Y Combinator Blog
J
Java Code Geeks
I
Intezer

博客园 - Waver

Tabbing problems in Firefox in Mac OS X [转] Data Flow Diagrams Tutorial [转] HTML Ampersand Character Codes 也谈完美跨域,JavaScript [转] 浏览器类型检测. (JavaScript) 【转】 Route命令使用详解[转] 使用塑料水瓶要当心 Extension Method for ENUM. Design Material Websites Summarization. - Waver How to cut through the complexity to find a solution. How to install flash player on Google Chrome browser? ADODB.Stream 对象的属性与方法 VB/VBScript读取和保存UTF-8文件方案 VB6: How To Convert UTF-8 Byte Arrays into Unicode Strings (and vice versa) Perl Unicode全攻略 ASP+COM 组件开发 SQL高级语法 无法去掉“关闭高级语言服务”解决方案! GCT 英语单词全部核心词汇A-Z GCT 工硕英语词汇语法
Perl和OLE Automation
Waver · 2008-08-28 · via 博客园 - Waver

   OLE是一种基于COM的技术。OLE允许应用程序使用其他应用程序提供的通用接口来访问其组件和功能。而在Perl里使用Win32::OLE模块,来实现对OLE对象的支持。
    实现Automation接口的应用程序(或者DLL动态链接库)被称作 Automation Server。而创建并使用Automation接口的应用程序被称做 Automation Controller 或者 Automation Client 。许多应用程序,比如 Microsoft Word,Excel,Access,以及其他 Office 应用程序等等,都已经实现了 Automation 接口。Automation 被广泛使用在 ASP,CGI 脚本中,通过 ADO 技术来存取某个 Data Respository。
    为了创建一个 Automation 对象,Automation Server 需要在系统中注册一下自己。一般来说,一个应用程序在安装时,已经帮你做了这一步,当然啦,即便没有,那么你也可以使用 regsrv32.exe 这样的工具来手动注册你的应用。这将在系统的注册表中插入一个条目,来告诉COM如何找到这个组件,它提供了什么类型的接口,它是什么类型的 Automation Server 。你能在一个应用程序的文档中找到有关它的 Automation 对象,以及相关信息。使用Perl语法同样能够创建这样的对象并访问它的组件。
    以下的就是Perl跟 Automation 相关的基本功能模块。
    Win32::OLE
        提供Perl对OLE Automation技术最主要的支持。通过这个模块,你能创建并使用 Automation 对象,调用对象的方法,配置对象的属性。
    Win32::OLE::Enum
        创建 Collections 对象,并提供接口枚举其中的项目。
    Win32::OLE::Variant
        允许你转换相关数据类型成OLE中的Variant数据类型。
    Win32::Const
        将Automation对象的常量导入到你Perl脚本中去。
注:Win32::OLE 目前还不支持 OCXs 和 OLE 事件。Win32::OLE 仅实现了 IDispatch 接口,因此它还不能存取一个客户化的 OLE 接口。

1.    创建对象
    Automation 对象在Perl里面用 Win32::OLE 对象的实例来替代。Win32::OLE 提供了三个构建器来创建一个注册了的Automation 对象。

  • new
  • GetActiveObject
  • GetObject

    2.    Automation 方法和属性
        一旦你创建了一个 Automation 对象,你就可以调用对象的方法,如果需要你还可以调整对象的属性。Automation 对象方法调用用Perl语法来表示:
        $obj->some_method( args );
    Automation 对象方法通常都会需要很多参数。如果你不想要任何一个参数,你可以在参数表里用undef来代替。
        $xl->WorkBooks(1)->SaveAs( $f , undef , undef , undef  , undef , 1 , undef , undef , 1 );
        你也可以用一个包含命名参数赋值的hash 散列的引用来作为参数。上面这个例子也可以这样写:
        $xl->WorkBooks(1)->SaveAs( $f , {AddtoMru => 1 , CreateBackup => 1});
        Automation 对象的属性可以用hash符号来访问。比如:
        $value = $obj->{“property“};
        $obj->{“property“} = $value;
        你也能枚举一个Automation的属性,用下面的方法:
        $xl = Win32::OLE->new(“Excel.Application“);
        while ( ($key,$value) = each %$xl)
        {
            print “$key = $value \n“;
        }

    2.    Win32::OLE 方法
        Win32::OLE 定义了一些它自己的方法来处理 Automation 接口。这些方法不是 Automation 定义的方法,虽然它们好像看起来是。如果一个方法在Win32::OLE 中没有定义,那么方法调用就被传递到 Automation 对象。如果 Automation 对象也没有定义。那么你将会得到一个 OLE 错误。
        下面是在Win32::OLE 中定义的方法。

  • Invoke
  • LastError
  • QueryObjectType

    3.    Win32::OLE函数
        下面是在Win32::OLE中定义的函数。缺省没有导出来。

  • in
  • valof
  • with

    4.    Win32::OLE 类变量
        Win32::OLE 定义了某些类变量来配置 Automaion 使用的缺省行为。
    $Win32::OLE::CP
        确定在Perl 字符串和Automation 接口Unicode之间转换的 codepage。
        缺省值是 CP_ACP,标识 ANSI codepage。
    $Win32::OLE::LCID
        控制所有 OLE 调用的 locale identifier。它缺省被设置为LOCAL_NEUTRAL。
    $Win32::OLE::Warn
        定义了当错误发生时,Win32::OLE 的行为。