Asp.net 使用weboffice实现Word在线编辑

摘要:
在项目中,客户需要在页面中实现Word的在线编辑、Word写保护等功能。使用Word 2003和Word 2007时,页面卡有问题。现在我找到了另一个组件,单击该公司的weboffice,这很好。对于weboffice的使用,您可以查看官方网站,那里有一个演示。用户可以在线编辑后将文档上传到服务器。实现方法如下:js处理:code varSaveinfo=function(){try{varid=getUrlPara;varwebObj=document.getElementById;webObj.HttpInit();//初始化Http引擎。//添加相应的Post元素webObj.HttpAddPostString;varstate=“0”;if{state=“1”;}webObj。HttpAddPostString;//webObj。HttpAddPostString;webObj。HttpAddPostCurrFile;//上载文件returnValue=webObj HttpPost;//如果{alert(“修改成功,请更新列表页!”);}elseiflat;}捕获{alert;}}保存文档。ashx执行文件处理:在这里我创建了一个新的doc文件。

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

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

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

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

js处理:

Asp.net 使用weboffice实现Word在线编辑第1张Asp.net 使用weboffice实现Word在线编辑第2张代码
 

  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文件。

Asp.net 使用weboffice实现Word在线编辑第3张Asp.net 使用weboffice实现Word在线编辑第4张代码
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

免责声明:文章转载自《Asp.net 使用weboffice实现Word在线编辑》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇pycharm添加conda解释器异常解决action中定义的方法能不能带参数?下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Android 3.0 r1 API中文文档(107) —— AsyncPlayer

前言   本章内容是android.media.AsyncPlayer,版本为Android 3.0 r1!期待你一起参与Android API的翻译,联系我over140@gmail.com。 声明   欢迎转载,但请保留文章原始出处:)     博客园:http://www.cnblogs.com/     Android中文翻译组:http:/...

vue pc端支付宝支付

===========HTML=================== <div v-html="payHtml" style="display:none"> {{payHtml}} </div>============JS=====================window.onload = function...

(转)iOS动画Core Animation

文章转载:http://blog.sina.com.cn/s/blog_7b9d64af0101b8nh.html 在iOS中动画实现技术主要是:Core Animation。  Core Animation负责所有的滚动、旋转、缩小和放大以及所有的iOS动画效果。其中UIKit类通常都有animated:参数部分,它可以允许是否使用动画。  Core A...

图片轮播插件-carouFredSel

carouFredSel图片轮播插件基于Jquery,比较常规的轮播插件,支持滚轮及键盘左右按键,加入其它插件可实现更加复杂的特效。 主页地址:http://caroufredsel.dev7studios.com/ 例子: html: 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitio...

.NET ActionFilterAttribute等

public override void OnException(HttpActionExecutedContext actionExecutedContext){//加LOG actionExecutedContext.Exception //2.返回调用方具体的异常信息if (actionExecutedContext.Exception is Not...

Neo4J图库的基础介绍(二)-图库开发应用

我们接着Neo4J图库的基础介绍(一)继续介绍Neo4J图库。 JAX-RS是一个用于构建REST资源的Java API,可以使用JAX-RS注解装饰每一个扩展类,从而让服务器处理对应的http请求,附加注解可以用来控制请求和响应的格式,http头和URI模板的格式。 下面看一个服务器扩展实现的示例,允许客户端请求社交网络的两个成员之间的距离 @Pa...