Office xp之后的版本支持通過webdav協(xié)議(http的擴(kuò)展)直接編輯服務(wù)器上的文件。
IIS(6.0)支持webdav,這在IIS管理器的web服務(wù)擴(kuò)展中可以看到.利用IIS作為webdav的服務(wù)器端,可以很容易的實(shí)現(xiàn)office(word,excel等)的在線編輯.
可以簡單的實(shí)驗(yàn)一下:
確保IIS的webdav擴(kuò)展安裝并被啟用了,建立一個(gè)虛擬目錄test,在其中放一個(gè)word文檔a.doc,然后打開word, 文件->打開->輸入word文檔的訪問url(http://localhost/test/a.doc),
修改一下文檔內(nèi)容,保存一下,發(fā)生了什么? 文檔被保存到服務(wù)器上了.
在IE中,可以通過js創(chuàng)建Word.Application,來打開,修改服務(wù)器上的文檔.
復(fù)制代碼 代碼如下:
wApp = new ActiveXObject("Word.Application.11");
wApp.Visible = true ;
wApp.Documents.Open( url );
if( trackRevisions ){ //可以實(shí)現(xiàn)痕跡保留呢
wApp.ActiveDocument.TrackRevisions = true ;
wApp.ActiveDocument.ShowRevisions = false ;
}else
{
wApp.ActiveDocument.TrackRevisions = false ;
wApp.ActiveDocument.ShowRevisions = false ;
}
wApp.ActiveDocument.Application.UserName= Global_CurrentUserName;
另外,安裝office時(shí),會(huì)同時(shí)按裝一個(gè)ActiveX組件:Sharepoint.OpenDocuments,可么用此組件來激活word,編輯服務(wù)器上的文檔: var __OpenDocuments = null ;
復(fù)制代碼 代碼如下:
function Document_Edit2( url )
{
if( __OpenDocuments == null )
{
try{
__OpenDocuments = new ActiveXObject("SharePoint.OpenDocuments.3"); //for office 2007
}catch(e){}
if( __OpenDocuments == null || typeof(__OpenDocuments) == "#ff0000" )
{
try{
__OpenDocuments = new ActiveXObject("SharePoint.OpenDocuments.2"); //for office 2003
}catch(e){}
}
if( __OpenDocuments == null || typeof(__OpenDocuments) == "undefined" )
{
alert( "請(qǐng)安裝Word(2003或更高版本)" );
return ;
}
}
// openDocObj.ViewDocument("http://www.abc.com/documents/sample.doc");, "Word.Document"
//openDocObj.CreateNewDocument("http://www.abc.com/documents/sampleTemplate.dot", "http://www.abc.com/documents/");
var result = __OpenDocuments.EditDocument( url , "Word.Document" );
if( result == false )
{
alert( "無法打開文檔." );
}
}
可以看到,基于IIS的webdav支持,可以非常簡單的實(shí)現(xiàn)office文檔的在線編輯, 但有一個(gè)問題:這樣,文檔是存放在文件系統(tǒng)上,我們很多系統(tǒng)中,
文檔是存放在數(shù)據(jù)庫中的,這樣一來,如何實(shí)現(xiàn)呢???
I tried a lot and found the solution. It will be in the next article .