DSOFramer.ocx 控件使用


DSOFramer.ocx 控件使用

接口文檔:

/*
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:頁數
*/ 
想在網頁中嵌入office組件,顯示office文件嗎?不防看看上面的文章,用起來,還不錯。

另:ASP.NET操作Word文檔


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM