使用DSOFramer全攻略

### 使用DSOFramer全攻略详解 #### 一、前言 DSOFramer 是一款功能强大的控件,可以用于处理 Office 文档,特别是对于 Web 应用程序而言,它提供了便捷的方式来展示、编辑甚至生成 Word、Excel 和 PowerPoint 文件。本文旨在通过 Asp.Net 2.0(C#)和 SQL Server 2005 的环境下详细介绍如何使用 DSOFramer 来实现这些功能。 #### 二、安装与配置 **1. 注册 DSOFramer.ocx** 需要将 DSOFramer.ocx 文件复制到 C:\windows\system32 目录下,并通过命令行进行注册。打开命令提示符,输入以下命令: ```cmd regsvr32 DSOFramer.ocx ``` 执行后,系统会提示注册成功的信息。 **2. 添加 DSOFramer 控件到项目中** 对于 Visual Studio 2005,可以通过以下步骤将 DSOFramer 添加到项目中: - 在解决方案资源管理器中,找到需要添加控件的项目文件夹。 - 右键点击该文件夹,选择“添加” -> “现有项”。 - 浏览并选中 DSOFramer.ocx 文件,然后点击“添加”。 #### 三、页面设计与脚本编写 **1. 在网页中加载 DSOFramer 控件** 为了在 ASP.NET 页面中显示 Office 文档,需要创建一个 ASPX 文件,并在其中嵌入 DSOFramer 控件的定义: ```html <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Office.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>DSOFramer 示例</title> <script type="text/javascript"> function show_word() { var str = window.location.search; var pos_start = str.indexOf("id") + 3; if (pos_start == 2) return; var id = "http://localhost/Getdc.aspx?id=" + str.substring(pos_start); document.getElementById('MyOffice').Open(id, false, "Word.Document"); } </script> </head> <body onload="show_word();"> <form id="form1" runat="server"> <object id="MyOffice" name="MyOffice" style="LEFT: 0px; WIDTH: 100%; TOP: 0px; HEIGHT: 100%" classid="clsid:00460182-9E5E-11D5-B7C8-B8269041DD57" codebase="dsoframer.ocx#version=2,2,0,0"> </object> </form> </body> </html> ``` **2. 编制 Getdc.aspx.cs 文件** 接下来,需要创建一个后台处理文件 `Getdc.aspx.cs`,用于从数据库中读取 Office 文档数据并发送给客户端。 ```csharp using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; using System.Data.SqlTypes; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { int pid = Convert.ToInt32(Request["id"]); string connectionString = "DataSource=localhost;InitialCatalog=demo;PersistSecurityInfo=True;UserID=demo;Password=demo"; using (SqlConnection myConnection = new SqlConnection(connectionString)) { SqlCommand myCommand = myConnection.CreateCommand(); myConnection.Open(); myCommand.CommandText = "SELECT filedata FROM Table_word WHERE ID = @PID"; myCommand.Parameters.AddWithValue("@PID", pid); SqlDataReader myReader = myCommand.ExecuteReader(); if (myReader.Read()) { SqlBinary binaryStream = myReader.GetSqlBinary(0); Response.Clear(); Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; Response.AddHeader("Content-Disposition", "inline; filename=Document.docx"); Response.BinaryWrite(binaryStream.Value); Response.End(); } myReader.Close(); myConnection.Close(); } } } ``` #### 四、总结 通过上述步骤,我们可以成功地在 ASP.NET 2.0 环境下利用 DSOFramer 控件实现对 Office 文档的处理。这种方法不仅可以提高 Web 应用程序的功能性,还能增强用户体验。需要注意的是,这里使用的 SQL Server 2005 和 DSOFramer 的版本可能与当前环境存在差异,因此在实际应用时还需要根据具体情况调整相应的代码和配置。 以上便是使用 DSOFramer 的全攻略,希望对你有所帮助。


















剩余7页未读,继续阅读

- bugcode2011-11-01这个资源真的很差,没有什么实质的内容,不过还是对楼主的分享表示感谢

- 粉丝: 17
- 资源: 6
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 机器学习-bert模型
- 【毕业设计】基于Python的Django-html基于语音识别的智能垃圾分类系统源码(完整前后端+mysql+说明文档+LW+PPT).zip
- ERA5再分析数据根区土壤水分下载_era5土壤湿度-CSDN博客.html
- 【毕业设计】基于Python的Django-html基于小波变换的数字水印研究系统源码(完整前后端+mysql+说明文档+LW+PPT).zip
- 【毕业设计】基于Python的Django-html基于知识图谱的百科知识问答平台源码(完整前后端+mysql+说明文档+LW+PPT).zip
- 【毕业设计】基于Python的Django-html开放领域事件抽取系统源码(完整前后端+mysql+说明文档+LW+PPT).zip
- 【毕业设计】基于Python的Django-html旅游城市关键词分析系统源码(完整前后端+mysql+说明文档+LW+PPT).zip
- 【毕业设计】基于Python的Django-html基于知识图谱的医疗问答系统源码(完整前后端+mysql+说明文档+LW+PPT).zip
- 【毕业设计】基于Python的Django-html某大学学生影响力分析系统源码(完整前后端+mysql+说明文档+LW+PPT).zip
- Unity RPG地图场景资源
- 【毕业设计】基于Python的Django-html棉花数据平台建设与可视化系统源码(完整前后端+mysql+说明文档+LW+PPT).zip
- hymenoptera-data 数据集
- Java I/O流及其应用详解:字节流、字符流及相关工具类全面解析
- 机器学习-apriori算法-超市关联分析
- 【毕业设计】基于Python的Django-html企业物流管理系统源码(完整前后端+mysql+说明文档+LW+PPT).zip
- 【毕业设计】基于Python的Django-html某医院体检挂号系统源码(完整前后端+mysql+说明文档+LW+PPT).zip


