DSOframer接口说明 .doc

上传人:laozhun 文档编号:2883047 上传时间:2023-03-01 格式:DOC 页数:26 大小:162KB
返回 下载 相关 举报
DSOframer接口说明 .doc_第1页
第1页 / 共26页
DSOframer接口说明 .doc_第2页
第2页 / 共26页
DSOframer接口说明 .doc_第3页
第3页 / 共26页
DSOframer接口说明 .doc_第4页
第4页 / 共26页
DSOframer接口说明 .doc_第5页
第5页 / 共26页
点击查看更多>>
资源描述

《DSOframer接口说明 .doc》由会员分享,可在线阅读,更多相关《DSOframer接口说明 .doc(26页珍藏版)》请在三一办公上搜索。

1、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);/新建Ex

2、celdocument.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,

3、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

4、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

5、.FramerControl1.HttpAddPostCurrFile(FileData, 文档名.doc);/执行上传动作document.all.FramerControl1.HttpPost( 1.1.4 修订痕迹/进入留痕状态document.all.FramerControl1.SetTrackRevisions(1);/进入非留痕状态document.all.FramerControl1.SetTrackRevisions(0);/接受当前修订document.all.FramerControl1.SetTrackRevisions(4);1.1.5 设置当前用户document.

6、all.FramerControl1.SetCurrUserName(张三); 1.1.6 设置和创建书签,此功能比较强大,设置书签数据、添加书签和添加红头文件SetFieldValue(BSTR strFieldName, BSTR strValue, BSTR strCmdOrSheetName)strFieldName:书签名strValue:要设置的值strCmdOrSheetName:命令 :ADDMARK: 添加BookMark:DELMARK: 删除这个BookMark:GETMARK: 定位到这个BookMark:FILE: 插入的是文件:JPG: 插入的是图片一般来说:WOR

7、D中书签是做好的,可以通过此接口把外界数据设置进书签中去。*/在当前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,插入红头文件http:/222.222.222.222/hongtou1.doc 这样,红头就自动插进去了docume

8、nt.all.FramerControl1.SetFieldValue(hongtou,http:/222.222.222.222/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

9、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 strFileNa

10、me, 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类型数据插入的限制,导致

11、当新增一条数据的时候无法直接插入数据到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_CONTE

12、XT(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 E

13、APValueObject 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 getBy

14、tes(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.len

15、gth; 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)对应到当前表

16、单 * 建议使用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类型字段操作,所以修改代码如下:p

17、ublic 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 EAPDAOExceptio

18、n(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 eapRe

19、sp) 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.do

20、Find(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,

21、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.getHttpReques

22、t().getParameter(rowId); reqEvent.getEAPRequest().setDefaultData(idList); return true; public ActionForward assembleResponse(EAPBizResponseEvent respEvent) assembleResponseForm(respEvent.getHttpRequest(), respEvent.getForm(), respEvent.getEAPResponse(); assembleResponseResult(respEvent.getHttpReques

23、t(), 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,脚本代码如下:%

24、/ 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(by

25、te)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_o

26、nclick_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.F

27、ramerControl1.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.

28、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, , ); /* 将文档作为大对象保存到数据库

29、*/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);/* 关闭文档

30、*/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()

31、 /初始化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/wo

32、rd/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=hidden name=programId v

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号