首页 >word操作 > 内容

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

2023年8月14日 21:15

项目中客户需要在页面中实现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(HttpContextcontext)
{
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(
" noright! " );
}

// ID为文档的主键,如果ID不为空,则更新数据,否则新建一条记录
string ID = context.Request.Params[ " ID " ];
if (context.Request.Files.Count > 0 )
{
HttpPostedFileupPhoto
= context.Request.Files[ 0 ];
int upPhotoLength = upPhoto.ContentLength;
byte []PhotoArray = new Byte[upPhotoLength];
StreamPhotoStream
= 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))
{
FileStreamfs
= 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(
" NoFileUpload! " );
}
}

public bool IsReusable
{
get
{
return false ;
}
}
}
复制代码

相关实例: 1。ex1

2.ex2


参考文章:https://blog.csdn.net/shan1774965666/article/details/39693819

郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时候联系我们修改或删除,在此表示感谢。

特别提醒:

1、请用户自行保存原始数据,为确保安全网站使用完即被永久销毁,如何人将无法再次获取。

2、如果上次文件较大或者涉及到复杂运算的数据,可能需要一定的时间,请耐心等待一会。

3、请按照用户协议文明上网,如果发现用户存在恶意行为,包括但不限于发布不合适言论妄图

     获取用户隐私信息等行为,网站将根据掌握的情况对用户进行限制部分行为、永久封号等处罚。

4、如果文件下载失败可能是弹出窗口被浏览器拦截,点击允许弹出即可,一般在网址栏位置设置

5、欢迎将网站推荐给其他人,网站持续更新更多功能敬请期待,收藏网站高效办公不迷路。

      



登录后回复

共有0条评论