Office文檔在線編輯的一個實(shí)現(xiàn)方法
更新時間:2010年06月19日 17:52:10 作者:
因?yàn)轫?xiàng)目的關(guān)系,研究了一下Office的在線編輯功能,寫出來共享一下。
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ò)展安裝并被啟用了,建立一個虛擬目錄test,在其中放一個word文檔a.doc,然后打開word, 文件->打開->輸入word文檔的訪問url(http://localhost/test/a.doc),
修改一下文檔內(nèi)容,保存一下,發(fā)生了什么? 文檔被保存到服務(wù)器上了.
在IE中,可以通過js創(chuàng)建Word.Application,來打開,修改服務(wù)器上的文檔.
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時,會同時按裝一個ActiveX組件:Sharepoint.OpenDocuments,可么用此組件來激活word,編輯服務(wù)器上的文檔: var __OpenDocuments = null ;
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( "請安裝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文檔的在線編輯, 但有一個問題:這樣,文檔是存放在文件系統(tǒng)上,我們很多系統(tǒng)中,
文檔是存放在數(shù)據(jù)庫中的,這樣一來,如何實(shí)現(xiàn)呢???
I tried a lot and found the solution. It will be in the next article .
IIS(6.0)支持webdav,這在IIS管理器的web服務(wù)擴(kuò)展中可以看到.利用IIS作為webdav的服務(wù)器端,可以很容易的實(shí)現(xiàn)office(word,excel等)的在線編輯.
可以簡單的實(shí)驗(yàn)一下:
確保IIS的webdav擴(kuò)展安裝并被啟用了,建立一個虛擬目錄test,在其中放一個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時,會同時按裝一個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( "請安裝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文檔的在線編輯, 但有一個問題:這樣,文檔是存放在文件系統(tǒng)上,我們很多系統(tǒng)中,
文檔是存放在數(shù)據(jù)庫中的,這樣一來,如何實(shí)現(xiàn)呢???
I tried a lot and found the solution. It will be in the next article .
相關(guān)文章
kindSoft在線網(wǎng)頁編輯器簡單的配置參數(shù)介紹
對于網(wǎng)頁編輯器對做項(xiàng)目的時候是非常的又用的一個編輯器,大大的減輕了開發(fā)人員的負(fù)擔(dān),感覺KindSoft是一個不錯的選擇,因此也在不斷的使用接下來介紹參數(shù)配置,需要的朋友可以了解下2013-01-01Ewebeditor及fckeditork單引號問題的解決方法
為什么一個簡單的單引號會引發(fā)不能添加到數(shù)據(jù)庫呢,想到這里,我們想到了分析下入庫代碼并找出了原因,下面是解決方法。2010-04-04解決SyntaxHighlighter 代碼高亮不換行問題的解決方法
用SyntaxHighlighter 語法高亮插件的朋友可能都遇到過代碼顯示不換行的問題,這個問題在網(wǎng)上也找不到什么解決辦法,一直困擾了我很久,今天算是把它解決了,辦法其實(shí)簡單,下面說下如何解決2014-11-11KindEditor 4.x 在線編輯器常用方法小結(jié)
要修改默認(rèn)后臺程序處理文件,修改plugins(插件文件夾)下的JavaScript內(nèi)容fileManagerJson改為自己使用程序語言2011-11-11