一般而言
,
在
ASP
或
ASP.Net
中透过
CreateObject
建构函数建立
Word
对象
会有安全性及使用权限上的问题
,
因此若
虚拟目录
不使用
整合
Windows
验证
将无法存取
Word doc
檔
,更不用说虚拟目录以外的目录
,
好比说
C:/
根目录下的
Word
文件。
底下介绍个方式,给大家参考看看
:
l
使用
VB6
n
建立项目,选择
ActiveX DLL
n
将项目的
Name
属性设定成
Ax
,
Class
的
Name
属性设为
Word
n
编辑程序代码如下
:
n
|
n
编译
制成
DLL
Compiler
完成后请使用
RegSvr32.exe
将该
Dll
组件
"
反注册
"
,
如
RegSvr32 /u "
路径
+
文件名
.dll"
RegSvr32.exe
工具使用
可参考
:
<<
关于
ActiveX (OLE)
组件登录注册
>>
l
执行
DCOMCNFG.EXE
-> [
确定
]
n
COM+
应用程序
->
鼠标右键
->
新增
->
应用程序
n
[
下一步
] ->
建立空的应用程序
n
输入应用程序名称
->
伺服应用程序
-> [
下一步
]
n
使用下列使用者
->
使用者
->
密码
/
确认密码
-> [
下一步
] -> [
完成
]
u
输入
Administrator
及密码
n
AxWord ->
组件
->
鼠标右键
->
新增
->
组件
-> [
下一步
]
n
[
安装新组件
]
n
选取
先前用
VB6
编译制成的
DLL
n
[
下一步
] -> [
完成
]
l
ASP Code
如下
:
n
|
================================================================
以上方式是使用
VB6
,
将
Word
对象
作动
的部份
写成
ActiveX Dll
,
在放到组件服务里的
COM+
中,并指定
Administrator
去执行,以避开安全性上的权限问题;
但倘若手边没有
VB6
开发工具呢
?
底下介绍
WSC
的方式
,只要文字文件不需
VB6
啰
!
WSC ( Windows Script Component )
l
建立一新
文字文件
n
编辑程序代码如下
:
n
|
n
存档
命名为
AxWord.wsc (
注意扩展名为
WSC )
n
选取档案
->
鼠标右键
->
注册
->
出现注册
是否成功
的讯息
-> [
确定
]
n
选取档案
->
鼠标右键
->
建立型态链接库
u
(
会产生一
ScriptLet.tlb
的
Type Library
档案
)
n
之后如同
ActiveX Dll
安装于组件服务中的动作
n
直到
[
安装新组件
]
时,请选择
ScriptLet.tlb
档案
n
完成后画面如下
:
l
ASP Code
如下
:
n
|