DSOframer接口说明.doc_第1页
DSOframer接口说明.doc_第2页
DSOframer接口说明.doc_第3页
DSOframer接口说明.doc_第4页
DSOframer接口说明.doc_第5页
已阅读5页,还剩21页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

office在线编辑功能实现1 dsoframer控件说明dsoframer.ocx控件是微软提供一款开源的用于在线编辑、调用word、 excel 、powerpoint等的activex控件。国内很多著名的oa中间件,电子印章,签名留痕等大多数是依此改进而来的。只要本地安装注册dsoframer控件,并且安装了office软件,即可实现其强大的在线编辑功能。1.1 dsoframer控件接口在jsp页面中添加如下脚本代码,实现控件的引用: 1.1.1 新建文档/新建word/document.all.framercontrol1.createnew(word.document);/新建exceldocument.all.framercontrol1.createnew(excel.sheet);1.1.2 打开文档/打开制定的本地文件document.all.framercontrol1.open(c:testbook.xls);/制定用word来打开c:plain.txt文件document.all.framercontrol1.open(c:plain.txt,false, word.document);/打开服务器的文件 document.all.framercontrol1.open https:/secureserver/test/mytest.asp?id=123,true, excel.sheet, myuseraccount, mypassword);/打开服务器的文件 document.all.framercontrol1.open(http:/localhost/1.doc, true);1.1.3 保存文档*/到本地document.all.framercontrol1.save(c:1.doc,true);/服务器 /*增加http协议post上传接口,可以post一个动态页面(jsp,asp,php.),由动态页面负责解析数据bool httpinit();bool httpaddpoststring(bstr strname, bstr strvalue);bool httpaddpostcurrfile(bstr strfileid, bstr strfilename);bstr httppost(bstr bstr); */初始化http引擎document.all.framercontrol1.httpinit();/增加post变量document.all.framercontrol1.httpaddpoststring(recordid,20060102200);document.all.framercontrol1.httpaddpoststring(userid,李局长);/上传打开的文件document.all.framercontrol1.httpaddpostcurrfile(filedata, 文档名.doc);/执行上传动作document.all.framercontrol1.httppost(/uploadfile.asp); 1.1.4 修订痕迹/进入留痕状态document.all.framercontrol1.settrackrevisions(1);/进入非留痕状态document.all.framercontrol1.settrackrevisions(0);/接受当前修订document.all.framercontrol1.settrackrevisions(4);1.1.5 设置当前用户document.all.framercontrol1.setcurrusername(张三); 1.1.6 设置和创建书签,此功能比较强大,设置书签数据、添加书签和添加红头文件setfieldvalue(bstr strfieldname, bstr strvalue, bstr strcmdorsheetname)strfieldname:书签名strvalue:要设置的值strcmdorsheetname:命令 :addmark: 添加bookmark:delmark: 删除这个bookmark:getmark: 定位到这个bookmark:file: 插入的是文件:jpg: 插入的是图片一般来说:word中书签是做好的,可以通过此接口把外界数据设置进书签中去。*/在当前word位置插入标签,标签名为book1,数值为testdocument.all.framercontrol1.setfieldvalue(book1,test,:addmark:);/设置书签time,数值为2006-03-16 22:22:22document.all.framercontrol1.setfieldvalue(time,2006-03-16 22:22:22,);/在书签位置hongtou,插入红头文件22/hongtou1.doc 这样,红头就自动插进去了document.all.framercontrol1.setfieldvalue(hongtou,22/hongtou1.doc,:file:);1.1.7 删除本地文件hresult deletelocalfile(in bstr strfilepath); 参数: strfilename:文件本地路径,如c:11.doc 1.1.8 创建临时文件hresult gettempfilepath(out,retval bstr* strvalue); 返回: 临时文件的路径地址。使用完后,用deletelocalfile 删除1.1.9 下载远程文件hresult downloadfile( in bstr strremotefile, in bstr strlocalfile, out,retval bstr* strvalue); 参数: strremotefile:远程路径地址,http or ftp strlocalfile: 本地保存地址,if strlocalfile = null then create temp file and return tempfiles path1.1.10 增加http上传时候的,附加其他文件hresult httpaddpostfile(in bstr strfileid, in bstr strfilename, out,retval long* pbool);参数: strfileid:文件的id,供服务器端页面解析 strfilename: 本地文件地址 1.2 在unieap中的应用我们现在以实例演示在unieap框架中使用,首先在数据库中创建一张test_word表:create table test_word ( row_id number not null, context blob, primary key (row_id) )其中context字段用于保存文件,其类型为blob。1.2.1 修改*-oracle.xml文件由于oracale数据库对blob类型数据插入的限制,导致当新增一条数据的时候无法直接插入数据到blob类型的字段中,所以我们必须:1. 插入一条blob类型字段为空的记录。2. 对刚才新插入的那条数据执行更新操作,将文件数据以字节数组形式更新到对应的blob类型字段中。所以我们要修改dao层下的*-oracle.xml文件: 1.2.2 修改vo对于blob类型的字段,使用代码生成器生成的vo所对应的字段类型是string的,所以要修改为byte类型,代码如下:private byte tw_context; public byte gettw_context() return tw_context; public void settw_context(byte tw_context) this.tw_context = tw_context;1.2.3 修改form因为页面的word文件需要通过form传到后台,所以在form中对应于blob类型字段的变量就不能为string类型了,而是设置为formfile类型:private formfile tw_context;public formfile gettw_context() return tw_context; public void settw_context(formfile tw_context) this.tw_context = tw_context;public eapvalueobject transform() wordvo vo = new wordvo(); vo.settw_row_id(eapdataformat.parsestring(tw_row_id, vo.gettw_row_id(); try inputstream inputstream = tw_context.getinputstream(); vo.settw_context(getbytes(inputstream); catch(exception ex) return vo; /将inputstream类型转换为字节数组public static byte getbytes(inputstream is) throws exception byte data = null; collection chunks = new arraylist(); byte buffer = new byte1024*1000; int read = -1; int size = 0; while(read=is.read(buffer)!=-1) if(read0) byte chunk = new byteread; system.arraycopy(buffer,0,chunk,0,read); chunks.add(chunk); size += chunk.length; if(size0) bytearrayoutputstream bos = null; try bos = new bytearrayoutputstream(size); for(iterator itr=chunks.iterator();itr.hasnext();) byte chunk = (byte)itr.next(); bos.write(chunk); data = bos.tobytearray(); finally if(bos!=null) bos.close(); return data; /* * 父类抽象方法实现 * 将传入的数据对象(vo)对应到当前表单 * 建议使用eapdataformat.tostring()进行类型转换 * */ public void transform(eapvalueobject _vo) wordvo vo = (wordvo)_vo; tw_row_id = eapdataformat.tostring(vo.gettw_row_id(); 注意:其中将传入的数据对象(vo)对应到当前表单方法中不需要对vo中的blob类型字段做转换。1.2.4 修改dao前面我们已经说过了,由于oracle本身的限制,在对blob类型数据新增操作的时候需要执行先插入空blob在更新blob类型字段操作,所以修改代码如下:public boolean doinsertbyvo(eapvalueobject vo) throws eapdaoexception boolean result = true; wordvo wordvo = (wordvo)vo; try result = daocommand.sm_insert(this.getnamespace()+.+sql_insert_by_vo, vo); if(result) result = doupdatebyvo(wordvo); return result; catch(exception ex) throw new eapdaoexception(ex); public boolean doupdatebyvo(eapvalueobject vo) throws eapdaoexception try return daocommand.sm_update(this.getnamespace()+.+sql_update_by_vo, vo); catch(exception ex) throw new eapdaoexception(ex); 1.2.5 修改service添加dogetfiledata方法:public void dogetfiledata(eaprequest eapreq, eapresponse eapresp) throws eapserviceexception commonbizinvoke(eapreq, eapresp, new eapbizservicehandleimpl(false) public boolean process(eaprequest eapreq, eapresponse eapresp) long idlist = (long)eapreq.getdefaultdata(); eapvalueobject vo = null; eapbizbo bo = getactivebo(); if(bo!=null & idlist!=null) vo = bo.dofind(eapreq.getusertoken(), idlist0); wordvo wordvo = (wordvo)vo; eapresp.setdata(tw_context_byte,wordvo.gettw_context(); eapresp.setdefaultdata(vo); return true; );1.2.6 修改action添加dogetfiledata方法:public actionforward dogetfiledata(actionmapping mapping, actionform form, httpservletrequest request, httpservletresponse response) throws exception return monbizinvoke(mapping, form, request, response, this.getservicename(), dogetfiledata, new eapbizactionhandleimpl() public boolean assemblerequest(eapbizrequestevent reqevent) long idlist = new long1; idlist0 = long.parselong(reqevent.gethttprequest().getparameter(rowid); reqevent.geteaprequest().setdefaultdata(idlist); return true; public actionforward assembleresponse(eapbizresponseevent respevent) assembleresponseform(respevent.gethttprequest(), respevent.getform(), respevent.geteapresponse(); assembleresponseresult(respevent.gethttprequest(), respevent.geteapresponse(); respevent.gethttprequest().setattribute(file_data,(byte)respevent.geteapresponse().getdata(tw_context_byte); return respevent.getmapping().findforward(getfiledata); );1.2.7 修改模块的struts-config.xml文件添加一个页面重定向路径:1.2.8 添加jsp等相关文件1. 添加加载数据库文件数据的jsp文件:readdata.jsp,脚本代码如下:%/ servletoutputstream sos=response.getoutputstream(); try /string type = request.getparameter(type) = null ? image/pjpeg : request.getparameter(type); response.setcontenttype(application/msword); int len = (byte)request.getattribute(file_data).length; inputstream stream = new bytearrayinputstream(byte)request.getattribute(file_data); sos.write(byte)request.getattribute(file_data),0,len); sos.close(); catch(exception ex) %2. 添加dsoframer.ocx文件统一放置在一个公用的配置文件夹中。3. 添加模板文件统一将业务需求的所有模板文件放置于一个公用的文件夹中。1.2.9 修改adddedit.jsp页面我们将在这里加载dsoframer控件,实现在线office文档编辑、保存、上传等操作,代码如下:/* 打开服务器文档 */function command_onclick_openserver() document.all.framercontrol1.open(/test/testword/word/template1.doc, true);/* 以服务器模板文档创建新文档 */function command_onclick_openmodeldocu() document.all.framercontrol1.createnew(/test/testword/word/template1.doc); document.all.framercontrol1.setfieldvalue(mtl_name,交换机,); document.all.framercontrol1.setfieldvalue(count,9999,); document.all.framercontrol1.setfieldvalue(sku,台,); document.all.framercontrol1.setfieldvalue(amt,999999,);/* 插入红头文件 */function command_onclick_insertfile() document.all.framercontrol1.createnew(/test/testword/word/template1.doc); document.all.framercontrol1.setfieldvalue(title,/test/testword/word/redtitle.doc,:file:);/* 打开数据库文档 */function command_onclick_opendatabase() var url = test/testword/word/word.do?method=dogetfiledata&rowid=”&type=application/msword; alert(url); document.all.framercontrol1.open(url, false, word.document, , ); /* 将文档作为大对象保存到数据库 */function command_onclick_savetodatabase() var success = savedocumenttodb(); if (success = true) alert(save word document success); else alert(save error! please try again after!); return false;/* 保存到本地临时文档 */function command_onclick_save() document.all.framercontrol1.save(c:temp.doc,true);/* 关闭文档 */function command_onclick_close() document.all.framercontrol1.close();/* 删除本地临时文档 */function command_onclick_delete() /请注意不能删除正被打开的文件,所以上传完后要先关闭文件再删除。 command_onclick_close(); document.all.framercontrol1.deletelocalfile(c:temp.doc);/* 保存文件到数据库,同时将文档另存为本地html文件后一起传到服务器端 */function savedocumenttodb() /初始化http引擎 document.all.framercontrol1.httpinit(); /模拟表单域,设置参数 document.all.framercontrol1.httpaddpoststring(scsj,2008-5-16 00:00:00); document.all.framercontrol1.httpaddpoststring(gzljdid,2); /上传打开的文件 document.all.framercontrol1.httpaddpostcurrfile(tw_context, ); /执行上传动作 var url = test/testword/word/word.do?method=doadd; try var tar = document.all.framercontrol1.httppost(url); catch(e) return false; finally return true;/* 文档对象初始化 */function framercontrol1_init() document.all.framercontrol1.createnew(word.document); document.all.framercontrol1.activedocument.content.text = 测试员,你好!;input type=hidde

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论