ASP 如何读取 Word 档案内容并显示于网页
来源:互联网 发布:桔子瑜伽怎么样 知乎 编辑:程序博客网 时间:2024/04/27 18:00
一般而言,在 ASP 或 ASP.Net 中透过 CreateObject 建构函数建立 Word 对象
会有安全性及使用权限上的问题,因此若虚拟目录不使用整合 Windows 验证
将无法存取 Word doc 檔,更不用说虚拟目录以外的目录 ,好比说 C:/ 根目录下的 Word 文件。
底下介绍个方式,给大家参考看看:
l 使用 VB6
n 建立项目,选择 ActiveX DLL
n 将项目的 Name属性设定成 Ax,Class 的 Name 属性设为 Word
n 编辑程序代码如下 :
n
Public Function GetDocContent(strFile As String) As String
Dim wdObj As Object ' 宣告
Set wdObj = CreateObject("Word.Application") ' 個體化 Word 物件
With wdObj
.Documents.Open strFile ' 開啟 Word 檔
GetDocContent = .ActiveDocument.Content ' 讀出 Word 內容囉
' 底下關掉 Word 檔 , 釋放資源
On Error Resume Next
.ActiveDocument.Close
.ActiveWindow.Close
.Quit
End With
Set wdObj = Nothing
End Function
n 编译制成 DLL
Compiler 完成后请使用 RegSvr32.exe 将该 Dll 组件"反注册" , 如
RegSvr32 /u "路径+文件名.dll"
RegSvr32.exe 工具使用可参考:
<< 关于 ActiveX (OLE) 组件登录注册 >>
http://blog.blueshop.com.tw/hammerchou/archive/2006/04/06/20787.aspx
l 执行 DCOMCNFG.EXE -> [确定]
n COM+应用程序 -> 鼠标右键 -> 新增 -> 应用程序
n [下一步] -> 建立空的应用程序
n 输入应用程序名称 -> 伺服应用程序 -> [下一步]
n 使用下列使用者 -> 使用者 -> 密码 / 确认密码 -> [下一步] -> [完成]
u 输入 Administrator 及密码
n AxWord -> 组件 -> 鼠标右键 -> 新增 -> 组件 -> [下一步]
n [安装新组件]
n 选取先前用 VB6 编译制成的 DLL
n [下一步] -> [完成]
l ASP Code 如下:
n
<%
' 宣告
Dim wd
' 建立先前寫的 DLL 物件 , 個體化
Set wd = Server.CreateObject("AX.Word")
' 執行 Dll 中的 GetDocContent 方法讀 Word 內容
Response.Write wd.GetDocContent("C:/1.doc")
%>
================================================================
以上方式是使用 VB6 ,将 Word 对象作动的部份写成 ActiveX Dll ,
在放到组件服务里的 COM+ 中,并指定 Administrator 去执行,以避开安全性上的权限问题;
但倘若手边没有 VB6开发工具呢?底下介绍 WSC 的方式,只要文字文件不需VB6啰 !
WSC ( Windows Script Component )
l 建立一新文字文件
n 编辑程序代码如下 :
n
<?xml version="1.0"?>
<component>
<registration
description="PH ActiveX Word Windows Script Component"
progid="AxWsc.Word"
version="1.00"
classid="{5F644CD7-E1D4-4D54-A260-B4CCC2F540FC}">
</registration>
<public>
<method name="GetDocContent">
</method>
</public>
<script language="VBScript">
<![CDATA[
Function GetDocContent(strFile)
Dim wdObj
Set wdObj = CreateObject("Word.Application")
With wdObj
.Documents.Open strFile
GetDocContent = .ActiveDocument.Content
On Error Resume Next
.ActiveDocument.Close
.ActiveWindow.Close
.Quit
End With
Set wdObj = Nothing
End Function
]]>
</script>
</component>
n 存档命名为 AxWord.wsc ( 注意扩展名为 WSC )
n 选取档案 -> 鼠标右键 -> 注册 -> 出现注册是否成功的讯息 -> [确定]
n 选取档案 -> 鼠标右键 -> 建立型态链接库
u ( 会产生一 ScriptLet.tlb 的 Type Library 档案 )
n 之后如同 ActiveX Dll 安装于组件服务中的动作
n 直到 [安装新组件] 时,请选择 ScriptLet.tlb 档案
n 完成后画面如下 :
l ASP Code 如下:
n
<%
' 宣告
Dim wd
' 建立先前寫的 DLL 物件 , 個體化
Set wd = Server.CreateObject("AxWsc.Word")
' 執行 Dll 中的 GetDocContent 方法讀 Word 內容
Response.Write wd.GetDocContent("C:/1.doc")
%>
- ASP 如何读取 Word 档案内容并显示于网页
- C#读取word文档内容并显示
- jcaob中读取word中的内容,并显示出来
- C#如何读取word内容
- 如何读取EXCEL 表格文件并使他在WEB网页上显示(使用ASP.NET)
- php读取word\pdf等文档的内容,并将其保存到网页中
- ASP.NET实现将网页内容输出到WORD并下载到本地
- 采用jacob读取并在网页中显示ppt、word、excel
- ASP.NET C#如何读取word,写入word,复制内容到另一个word文档,批量修改文件名
- ASP.net:读取Word内容(包含表格,不包含图片)并且显示在页面中
- ASP.net:读取Word内容(包含表格,不包含图片)并且显示在页面中
- java下载网页并读取内容
- java读取网页内容,并保存
- 上传word文档并显示内容
- 远程读取中文网页内容并显示, keyword: html, stringWithContentsOfURL encoding
- 远程读取中文网页内容并显示, keyword: html, stringWithContentsOfURL encoding
- 利用asp读取网页内容实例
- asp.net页面显示word文档内容
- XSLT学习(2)
- 军训的苦与甜
- 推荐一个.net下学习水晶报表的好程序兼ms sql server的好助手
- 就可以看到中文,保存后内容会自动转为unicode
- F1~F12键的功能和作用的详解
- ASP 如何读取 Word 档案内容并显示于网页
- 关于学习与创业——给大学生的一些建议
- 偶像:郑源(资料)
- 文件锁定解锁
- 大学生不是专业的奴隶
- 显示隐藏层...简单实现
- 网上找到的,记下来(API函数1)
- dbms_stats 使用详解
- 扫出心中的污泥浊水