Dsoframer實現文檔在線瀏覽功能

Dsoframer實現文檔在線瀏覽的原理相對簡單,至關於將office的桌面窗口嵌入了瀏覽器。可是微軟發佈的這個ActiveX插件好久不更新了,網上提供的下載大可能是國內大牛改寫的,版本不一。下面說下具體的實現吧,附件提供dsoframer的幫助文檔。php

一、在開發環境下注冊dsoframer.ocx。html

          DSOFramer.ocx複製到C:\windows\system32目錄下,開始->運行->regsvr32 DSOFramer.ocx , 系統會提示DSOFramer.ocx中的DllRegisterServer成功。web

    二、上傳文檔。spring

    網上上傳文件的代碼或者組件不少,大多集成在spring等框架下,在此就不上代碼了,具體根據本身項目架構選擇。可是須要說明的是,文檔上傳存在本地磁盤或者數據庫都是能夠的哦。數據庫

    三、文檔展現。windows

    

//新建word
document.getElementById('oframe').CreateNew("Word.Document");
//打開本地文檔
document.getElementById('oframe').Open("C:\\TestBook.xls");
//打開服務端代碼
document.getElementById('oframe').Open(serverPath+"audsource/getdoc.do?documentId="+audsourceId, false,"Word.Document");
//保存文件至本地
document.getElementById('oframe').Save("c:\\1.doc",true);
//保存文件至服務器
document.getElementById('oframe').HttpInit();//初始化
document.getElementById('oframe').HttpAddPostString("audsourceId",info.audsourceId);//k-v形式傳參
document.getElementById('oframe').HttpAddPostCurrFile("FileData","");//文件流
document.getElementById('oframe').HttpPost(webappName+'/audsource/updateDoc.do');//post提交


Dsoframer的幫助文檔說明很詳細,在此我也就不用作什麼代碼展現。可是根據本身使用過程當中遇到的問題仍是要爲你們分享下的。
瀏覽器

  • IE瀏覽器瀏覽時須要設置Internet選項。安全

    打開Internet選擇——安全——添加受信任的站點
服務器

    打開Internet選擇——安全——自定義級別——勾選對未標記爲安全執行腳本的ActiveX控件初始化並執行架構

    若是勾選後安裝不了dsoframer插件,那將其餘ActiceX選項根據狀況改成提示,安裝插件並非每臺機器這樣設置均可以成功安裝,少數瀏覽器不管怎麼設置都安裝不上,始終提示因爲安全問題被windows阻止。

  • 在編輯dsoframer打開的文檔時,連續兩次或屢次編輯文檔會致使IE瀏覽器奔潰,找不到解決的辦法。

  • IE6瀏覽器沒法再瀏覽器端註冊dsoframer控件,須要按開發環境註冊的方式去註冊。

  • 嵌入頁面的插件會存在頁面遮擋的問題,須要注意放進div作顯示隱藏的切換操做。

  • Dsoframer插件在線打開文檔只是其基礎功能,其提供word動態模板功能十分的強大,你們能夠根據幫助文檔試試。

Dsoframer用後給個人第一體會是:適合政府小用戶羣體。由於其穩定性較差不適合大用戶量。其製做word動態模板以及紅頭文件的功能很適合政府等行政單位。若是實在須要用到在線對office文檔的編輯、瀏覽、保存操做,能夠考慮使用pageoffice插件做爲替代,這是一款收費插件,兼容性穩定性都不錯。


DSO(dsoframer)的接口文檔

(開發環境)使用前先註冊一下DSOFramer.ocx
   
操做:將DSOFramer.ocx複製到C:\windows\system32目錄下,
        
開始->運行->regsvr32 DSOFramer.ocx , 系統會提示DSOFramer.ocx中的DllRegisterServer成功

DSO的接口文檔

/*
1.
新建
*/
//
新建Word
document.all.FramerControl1.CreateNew("Word.Document");
//
新建Excel
document.all.FramerControl1.CreateNew("Excel.Sheet");
/*
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);
/*
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("http://xxxx.com/uploadfile.asp");
/*
4.
修訂留痕
*/
//
進入留痕狀態
document.all.FramerControl1.SetTrackRevisions(1);
//
進入非留痕狀態
document.all.FramerControl1.SetTrackRevisions(0);
//
接受當前修訂
document.all.FramerControl1.SetTrackRevisions(4);
/*
5.
設置當前用戶
*/
document.all.FramerControl1.SetCurrUserName("
張三");       
/*
6.
設置當前時間(筆跡留痕會顯示("Like 2006:02:07 11:11:11")
*/
document.all.FramerControl1.SetCurrTime("2006:02:07 11:11:11");
/*
7.
設置和建立書籤,此功能比較強大,設置書籤數據、添加書籤和添加紅頭文件就靠他了
SetFieldValue(BSTR strFieldName, BSTR strValue, BSTR strCmdOrSheetName)
strFieldName:
書籤名
strValue
:要設置的值
strCmdOrSheetName

命令
::ADDMARK::   
添加BookMark
::DELMARK::         
刪除這個BookMark
::GETMARK::   
定位到這個BookMark
::FILE::                        
插入的是文件
::JPG::       
插入的是圖片
通常來講:WORD中書籤是作好的,能夠經過此接口把外界數據設置進書籤中去。
*/
//
在當前WORD位置插入標籤,標籤名爲"book1",數值爲"test"
document.all.FramerControl1.SetFieldValue("book1","test","::ADDMARK::");
//
設置書籤"Time",數值爲"2006-03-16 22:22:22"
document.all.FramerControl1.SetFieldValue("Time","2006-03-16 22:22:22","");
//
在書籤位置"hongtou",插入紅頭文件"http://222.222.222.222/hongtou1.doc" 這樣,紅頭就自動插進去了
document.all.FramerControl1.SetFieldValue("hongtou","http://222.222.222.222/hongtou1.doc","::FILE::");
/*
8.
設置菜單顯示狀況
BOOL SetMenuDisplay(long lMenuFlag)
lMenuFlag
爲如下數值的組合
#define MNU_NEW                         0x01
#define MNU_OPEN                        0x02
#define MNU_CLOSE                       0x04
#define MNU_SAVE                        0x08
#define MNU_SAVEAS                      0x16
#define MNU_PGSETUP                     0x64
#define MNU_PRINT                       0x256
#define MNU_PROPS                       0x32
#define MNU_PRINTPV                     0x126
*/
//
只有新建菜單可用
document.all.FramerControl1..SetMenuDisplay(1);
//
只有打開菜單可用
document.all.FramerControl1.SetMenuDisplay(2);
//
只有打開新建菜單可用
document.all.FramerControl1.SetMenuDisplay(3);
/*
9.
保護文檔和解保護文檔
lProOrUn:1:
保護文檔;0:解除保護
lProType: 
    wdNoProtection = -1,
    wdAllowOnlyRevisions = 0,
    wdAllowOnlyComments = 1,
    wdAllowOnlyFormFields = 2
strProPWD:
密碼
*/
//
徹底保護文檔,密碼爲"pwd"   
document.all.FramerControl1.ProtectDoc(1,1,"pwd");
//
解除文檔保護                
document.all.FramerControl1.ProtectDoc(0,1,"pwd");
/*
10.
顯示或隱藏修訂內容
ShowRevisions(long nNewValue)
nNewValue = 0
則隱藏修訂
          = 1
則顯示修訂
*/
//
顯示修訂留痕
document.all.FramerControl1.ShowRevisions(1);
//
隱藏修訂留痕
document.all.FramerControl1.ShowRevisions(0);
/*
11.
插入合併文件,
strFieldPath
文件路徑,能夠是http,ftp的路徑
pPos = 0 //
當前鼠標位置
1;
文件開頭
2;
文件末尾
pPos
的第4位爲1的時候,表明插入的是圖片
InSertFile(BSTR strFieldPath, long lPos)
*/
//
文件頭部插入文件
document.all.FramerControl1.InSertFile("http://XX.com/XX.doc",1);
//
文件尾部插入文件
document.all.FramerControl1.InSertFile("http://XX.com/XX.doc",2);
//
當前光標位置插入文件
document.all.FramerControl1.InSertFile("http://XX.com/XX.doc",0);
//
文件頭部插入圖片
document.all.FramerControl1.InSertFile("http://XX.com/XX.jpg",9);
//
文件尾部插入圖片
document.all.FramerControl1.InSertFile("http://XX.com/XX.jpg",10);
//
當前光標位置插入圖片
document.all.FramerControl1.InSertFile("http://XX.com/XX.jpg",8);
/*
0x31.
文檔另存爲
                HRESULT SaveAs([in] VARIANT strFileName, [in] VARIANT dwFileFormat, [out,retval] long* pbool);       
參數:
        strFileName
:文件本地路徑,如c:\\11.doc
        dwFileFormat:
文件格式
dwFileFormat
的數值爲:
Excel: Type
enum XlFileFormat
{
    xlAddIn = 18,
    xlCSV = 6,
    xlCSVMac = 22,
    xlCSVMSDOS = 24,
    xlCSVWindows = 23,
    xlDBF2 = 7,
    xlDBF3 = 8,
    xlDBF4 = 11,
    xlDIF = 9,
    xlExcel2 = 16,
    xlExcel2FarEast = 27,
    xlExcel3 = 29,
    xlExcel4 = 33,
    xlExcel5 = 39,
    xlExcel7 = 39,
    xlExcel9795 = 43,
    xlExcel4Workbook = 35,
    xlIntlAddIn = 26,
    xlIntlMacro = 25,
    xlWorkbookNormal = -4143,
    xlSYLK = 2,
    xlTemplate = 17,
    xlCurrentPlatformText = -4158,
    xlTextMac = 19,
    xlTextMSDOS = 21,
    xlTextPrinter = 36,
    xlTextWindows = 20,
    xlWJ2WD1 = 14,
    xlWK1 = 5,
    xlWK1ALL = 31,
    xlWK1FMT = 30,
    xlWK3 = 15,
    xlWK4 = 38,
    xlWK3FM3 = 32,
    xlWKS = 4,
    xlWorks2FarEast = 28,
    xlWQ1 = 34,
    xlWJ3 = 40,
    xlWJ3FJ3 = 41,
    xlUnicodeText = 42,
    xlHtml = 44
};
Word: Type
enum WdSaveFormat
{
    wdFormatDocument = 0,
    wdFormatTemplate = 1,
    wdFormatText = 2,
    wdFormatTextLineBreaks = 3,
    wdFormatDOSText = 4,
    wdFormatDOSTextLineBreaks = 5,
    wdFormatRTF = 6,
    wdFormatUnicodeText = 7,
    wdFormatEncodedText = 7,
    wdFormatHTML = 8
};
PPT:
enum PpSaveAsFileType
{
    ppSaveAsPresentation = 1,
    ppSaveAsPowerPoint7 = 2,
    ppSaveAsPowerPoint4 = 3,
    ppSaveAsPowerPoint3 = 4,
    ppSaveAsTemplate = 5,
    ppSaveAsRTF = 6,
    ppSaveAsShow = 7,
    ppSaveAsAddIn = 8,
    ppSaveAsPowerPoint4FarEast = 10,
    ppSaveAsDefault = 11,
    ppSaveAsHTML = 12,
    ppSaveAsHTMLv3 = 13,
    ppSaveAsHTMLDual = 14,
    ppSaveAsMetaFile = 15,
    ppSaveAsGIF = 16,
    ppSaveAsJPG = 17,
    ppSaveAsPNG = 18,
    ppSaveAsBMP = 19
};
*/
/*
0x32.
刪除本地文件
                        HRESULT DeleteLocalFile([in] BSTR strFilePath);       
參數:
        strFileName
:文件本地路徑,如c:\\11.doc                       
*/               
/*
0x33.
建立臨時文件
                HRESULT GetTempFilePath([out,retval] BSTR* strValue);       
返回:
   
臨時文件的路徑地址。使用完後,用DeleteLocalFile 刪除
*/
/*
0x34.
設置文檔顯示模式
                HRESULT ShowView([in] long dwViewType, [out,retval] long * pbool);       
dwViewType
的可取值爲:
enum WdViewType
{
    wdNormalView = 1,
    wdOutlineView = 2,
    wdPrintView = 3,
    wdPrintPreview = 4,
    wdMasterView = 5, //
這個是大綱
    wdWebView = 6
};
*/
//
大綱模式
document.all.FramerControl1.ShowView(5);
/*
0x39:
下載遠程文件
                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 TempFile's Path
*/
/*
0x40
:增長Http上傳時候的,附加其餘文件
                HRESULT HttpAddPostFile([in] BSTR strFileID, [in]  BSTR strFileName, [out,retval] long* pbool);
參數:
         strFileID
:文件的ID,供服務器端頁面解析
         strFileName:
本地文件地址
*/
/*
0x41,0x42.
獲取詳細的修訂信息。
   GetRevCount( [out,retval] long * pbool);
   GetRevInfo([in] long lIndex, [in]  long lType, [out,retval] BSTR* pbool);
  
例子以下
*/
var vCount;
vCount = document.all.FramerControl1.GetRevCount();
alert(vCount);
var vOpt = 0;
var vDate;
for(var i=1; i<= vCount; i++){
        vOpt = document.all.FramerControl1.GetRevInfo(i,2);
        if("1" == vOpt){
                vOpt = "
插入";
        }else if("2" == vOpt){
                vOpt = "
刪除";
        }else{
                vOpt = "
未知操做";
        }
        vDate = new String(document.all.FramerControl1.GetRevInfo(i,1));
        vDate = parseFloat(vDate);
        alert(vDate);
        dateObj = new Date(vDate);
  alert(dateObj.getYear()   + "
" + dateObj.getMonth() + 1 + "" + dateObj.getDate() +"" +  dateObj.getHours() +"" +  dateObj.getMinutes() +"" +  dateObj.getSeconds() +"" );
        alert("
用戶:"+document.all.FramerControl1.GetRevInfo(i,0) + "\r\n操做:" + vOpt + "\r\n內容:" + document.all.FramerControl1.GetRevInfo(i,3));
}
/*
0x43.
設置基本信息:
                HRESULT SetValue([in] BSTR strValue, [in]  BSTR strName, [out,retval] long* pbool);
1.
設置文件只讀密碼
        SetValue("password","::DOCPROP:PassWord");
2.
設置文件修改密碼
        SetValue("password","::DOCPROP:WritePW");
返回值:
0
正確
-1
:不支持此命令,請肯定您的第二個參數沒有傳錯
-127:
異常
*/
//
設置文件只讀密碼
document.all.FramerControl1.SetValue("password","::DOCPROP:PassWord");
//
設置文件修改密碼
document.all.FramerControl1.SetValue("password","::DOCPROP:WritePW");
/*
0x44.
設置文檔變量,這個不多能用到
                HRESULT SetDocVariable([in] BSTR strVarName, [in]  BSTR strValue,[in] long lOpt, [out,retval] long* pbool);
strVarName:
變量名
strVlaue:
變量值
lOpt:
操做類型,
按位
第一位爲1:  表示update域關聯的
第二位爲1:  表示若是沒有這個變量則添加
第三位爲1:  將來支持
return:
0:OK
-127:
異常
*/
/*
0x45:
分頁保存
HRESULT SetPageAs([in] BSTR strLocalFile, [in]  long lPageNum, [in]  long lType,[out,retval] long* pbool);
strLocalFile
:本地路徑
lPageNum
:頁數

相關文章
相關標籤/搜索