(開發環境)使用前先注冊一下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
0x45: 分頁儲存
HRESULT SetPageAs([in] BSTR strLocalFile, [in] long lPageNum, [in] long lType,[out,retval] long* pbool);
strLocalFile:本地路徑
lPageNum:頁數
轉自:
http://www.antzj.net/post/13.html