zoukankan      html  css  js  c++  java
  • Asp.net 使用weboffice实现Word在线编辑

    项目中客户需要在页面中实现Word的在线编辑,Word写保护等功能。之前写了篇文章,用的是dsoframer.ocx,参考的都是网络上的资源。用的时候页面卡,

    而且word2003和word2007有问题。现在找了个另外一个组件,点聚公司的weboffice,还不错。主要是免费的。

    关于weboffice的使用,大家可以看看官网,他那有演示。我这也把我找的资源和大家分享下。

    关于用户在线编辑后上传文档到服务器,实现方式如下:

    js处理:

    代码
     

      var Saveinfo = function() {
                try {
                    var id = getUrlPara("id");

                    var webObj = document.getElementById("WebOffice1");
                    webObj.HttpInit();   //初始化Http引擎
                    // 添加相应的Post元素
                    webObj.HttpAddPostString("id", id);
                    var state = "0";
                    if (document.getElementById("Checkbox1").checked == true) {
                        state = "1";
                    }
                    webObj.HttpAddPostString("state", state);
                    //  webObj.HttpAddPostString("DocID", myform.DocID.value);
                    webObj.HttpAddPostCurrFile("DocContent", "");  // 上传文件
                    returnValue = webObj.HttpPost("http://localhost:38706/AssessManage/AssessDocuments/weboffice/savedoc.ashx"); // 判断上传是否成功
                    if ("succeed" == returnValue) {
                        alert("修改成功,请更新列表页面!");
                    } else if ("failed" == returnValue)
                        alert("修改失败");
                } catch (e) {
                    alert("异常\r\nError:" + e + "\r\nError Code:" + e.number + "\r\nError Des:" + e.description);
                }
            }

    savedoc.ashx进行文件处理:

    这里我是创建一个新的doc文件。

    代码
    public class savedoc : IHttpHandler
        {

            
    public void ProcessRequest(HttpContext context)
            {
                context.Response.ContentType 
    = "text/plain";
                context.Response.Buffer 
    = true;
                context.Response.ExpiresAbsolute 
    = DateTime.Now.AddDays(-1);
                context.Response.AddHeader(
    "pragma""no-cache");
                context.Response.AddHeader(
    "cache-control""");
                context.Response.CacheControl 
    = "no-cache";

                Super.Wdxt.Kpgl.EnumList.UserIdentity _useridentity 
    = IdebtityBll.GetIndentityName(Super.Wdxt.Kpgl.Common.getUserBasicInfo.SchoolId(), Super.Wdxt.Kpgl.Common.getUserBasicInfo.UserId());
                
    if (_useridentity != Super.Wdxt.Kpgl.EnumList.UserIdentity.DeputyEnchou)
                {
                    context.Response.Write(
    "no right!");
                }

                
    //ID为文档的主键,如果ID不为空,则更新数据,否则新建一条记录
                string ID = context.Request.Params["ID"];
                
    if (context.Request.Files.Count > 0)
                {
                    HttpPostedFile upPhoto 
    = context.Request.Files[0];
                    
    int upPhotoLength = upPhoto.ContentLength;
                    
    byte[] PhotoArray = new Byte[upPhotoLength];
                    Stream PhotoStream 
    = upPhoto.InputStream;
                    PhotoStream.Read(PhotoArray, 
    0, upPhotoLength); //这些编码是把文件转换成二进制的文件
                    string Newfilename = Super.Wdxt.Kpgl.Common.Utils.NewName("")+"_"+Super.Wdxt.Kpgl.Common.getUserBasicInfo.UserId()+".doc";
                    
    string path = System.Configuration.ConfigurationManager.AppSettings["DocumentsPath"].ToString();
                    
    if (!File.Exists(Newfilename))
                    {
                        FileStream fs 
    = new System.IO.FileStream(path+Newfilename, System.IO.FileMode.CreateNew, System.IO.FileAccess.Write);
                        fs.Write(PhotoArray, 
    0, PhotoArray.Length);
                        fs.Close();
                    }
                    
    string state = context.Request.Params["state"];
                    
    bool flag=Super.Wdxt.Kpgl.BLL.AssessdocumentsBLL.Edit(ID, Newfilename, state);
                    
    if (flag)
                    {
                        context.Response.Write(
    "succeed");
                      }
                    
    else
                    {
                        context.Response.Write(
    "failed");
                    }
                   context.Response.End();

                    
    //-------------------------------------------
                }
                
    else
                {
                    context.Response.Write(
    "No File Upload!");
                }
            }

            
    public bool IsReusable
            {
                
    get
                {
                    
    return false;
                }
            }
        }

      相关实例: 1。ex1 

                    2.ex2

  • 相关阅读:
    Visual Studio 2010的活动,有兴趣的朋友可以来参加
    .NET 业务框架开发实战之九 Mapping属性原理和验证规则的实现策略
    Javascript 返回上一页
    Entity Framework 4.0新增对TSQL的支持
    .Net 4.0中支持的更加完善了协变和逆变
    c#4.0——泛型委托的协变、逆变
    JQuery 常用方法基础教程
    AspNetPager分页示例
    微软一站式示例代码浏览器
    UI与实体的映射
  • 原文地址:https://www.cnblogs.com/dooom/p/1770450.html
Copyright © 2011-2022 走看看