DSOframer接口說明_第1頁
DSOframer接口說明_第2頁
DSOframer接口說明_第3頁
DSOframer接口說明_第4頁
DSOframer接口說明_第5頁
已閱讀5頁,還剩21頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、office在線編輯功能實現(xiàn)1 dsoframer控件說明dsoframer.ocx控件是微軟提供一款開源的用于在線編輯、調用word、 excel 、powerpoint等的activex控件。國內很多著名的oa中間件,電子印章,簽名留痕等大多數(shù)是依此改進而來的。只要本地安裝注冊dsoframer控件,并且安裝了office軟件,即可實現(xiàn)其強大的在線編輯功能。1.1 dsoframer控件接口在jsp頁面中添加如下腳本代碼,實現(xiàn)控件的引用: 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協(xié)議post上傳接口,可以post一個動態(tài)頁面(jsp,asp,php.),由動態(tài)頁面負責解析數(shù)據(jù)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);/執(zhí)行上傳動作document.all.framercontrol1.httppost( 1.1.4 修訂痕跡/進入留痕狀態(tài)document.all.framercontrol1.settrackrevisions(1);/進入非留痕狀態(tài)document.all.framercontrol1.settrackrevisions(0);/接受當前修訂document.all.framercontrol1.settrackrevisions(4);1.1.5 設置當前用戶document.

6、all.framercontrol1.setcurrusername(張三); 1.1.6 設置和創(chuàng)建書簽,此功能比較強大,設置書簽數(shù)據(jù)、添加書簽和添加紅頭文件setfieldvalue(bstr strfieldname, bstr strvalue, bstr strcmdorsheetname)strfieldname:書簽名strvalue:要設置的值strcmdorsheetname:命令 :addmark: 添加bookmark:delmark: 刪除這個bookmark:getmark: 定位到這個bookmark:file: 插入的是文件:jpg: 插入的是圖片一般來說:wor

7、d中書簽是做好的,可以通過此接口把外界數(shù)據(jù)設置進書簽中去。*/在當前word位置插入標簽,標簽名為book1,數(shù)值為testdocument.all.framercontrol1.setfieldvalue(book1,test,:addmark:);/設置書簽time,數(shù)值為2006-03-16 22:22:22document.all.framercontrol1.setfieldvalue(time,2006-03-16 22:22:22,);/在書簽位置hongtou,插入紅頭文件22/hongtou1.doc 這樣,紅頭就自動插進去了docume

8、nt.all.framercontrol1.setfieldvalue(hongtou,22/hongtou1.doc,:file:);1.1.7 刪除本地文件hresult deletelocalfile(in bstr strfilepath); 參數(shù): strfilename:文件本地路徑,如c:11.doc 1.1.8 創(chuàng)建臨時文件hresult gettempfilepath(out,retval bstr* strvalue); 返回: 臨時文件的路徑地址。使用完后,用deletelocalfile 刪除1.1.9 下載遠程文件hresult

9、downloadfile( in bstr strremotefile, in bstr strlocalfile, out,retval bstr* strvalue); 參數(shù): 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);參數(shù): strfileid:文件的id,供服務器端頁面解析 strfilename: 本地文件地址 1.2 在unieap中的應用我們現(xiàn)在以實例演示在unieap框架中使用,首先在數(shù)據(jù)庫中創(chuàng)建一張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數(shù)據(jù)庫對blob類型數(shù)據(jù)插入的限制,導致

11、當新增一條數(shù)據(jù)的時候無法直接插入數(shù)據(jù)到blob類型的字段中,所以我們必須:1. 插入一條blob類型字段為空的記錄。2. 對剛才新插入的那條數(shù)據(jù)執(zhí)行更新操作,將文件數(shù)據(jù)以字節(jié)數(shù)組形式更新到對應的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類型轉換為字節(jié)數(shù)組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; /* * 父類抽象方法實現(xiàn) * 將傳入的數(shù)據(jù)對象(vo)對應到當前表

16、單 * 建議使用eapdataformat.tostring()進行類型轉換 * */ public void transform(eapvalueobject _vo) wordvo vo = (wordvo)_vo; tw_row_id = eapdataformat.tostring(vo.gettw_row_id(); 注意:其中將傳入的數(shù)據(jù)對象(vo)對應到當前表單方法中不需要對vo中的blob類型字段做轉換。1.2.4 修改dao前面我們已經(jīng)說過了,由于oracle本身的限制,在對blob類型數(shù)據(jù)新增操作的時候需要執(zhí)行先插入空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. 添加加載數(shù)據(jù)庫文件數(shù)據(jù)的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文件統(tǒng)一放置在一個公用的配置文件夾中。3. 添加模板文件統(tǒng)一將業(yè)務需求的所有模板文件放置于一個公用的文件夾中。1.2.9 修改adddedit.jsp頁面我們將在這里加載dsoframer控件,實現(xiàn)在線office文檔編輯、保存、上傳等操作,代碼如下:/* 打開服務器文檔 */function command_o

26、nclick_openserver() document.all.framercontrol1.open(/test/testword/word/template1.doc, true);/* 以服務器模板文檔創(chuàng)建新文檔 */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:);/* 打開數(shù)據(jù)庫文檔 */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, , ); /* 將文檔作為大對象保存到數(shù)據(jù)庫

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);/* 保存文件到數(shù)據(jù)庫,同時將文檔另存為本地html文件后一起傳到服務器端 */function savedocumenttodb()

31、 /初始化http引擎 document.all.framercontrol1.httpinit(); /模擬表單域,設置參數(shù) document.all.framercontrol1.httpaddpoststring(scsj,2008-5-16 00:00:00); document.all.framercontrol1.httpaddpoststring(gzljdid,2); /上傳打開的文件 document.all.framercontrol1.httpaddpostcurrfile(tw_context, ); /執(zhí)行上傳動作 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 na

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論