DsoFramer2

/*
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::   ::FILE::
一般來說: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);
/*
*/
document.all.FramerControl1.InSertFile("http://localhost/1.doc");


/*
11.設置文檔瀏覽模式
 ShowView(long dwViewType)

*/
//大綱模式
document.all.FramerControl1.ShowView(5);

/*
12.插入合併文件,
strFieldPath 文件路徑,可以是http,ftp的路徑

pPos = 0 //當前鼠標位置
1;文件開頭
2;文件末尾
 
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);



===================================================================
DSOFramer原有的接口說明
1.void CreateNew(BSTR ProgIdOrTemplate)
  新建文檔,
  其中: ProgIdOrTemplate參數:
Excel Spreadsheet     "Excel.Sheet" 
Excel Chart        "Excel.Chart" 
PowerPoint Presentation  "PowerPoint.Show" 
Project Project      "MSProject.Project" 
Visio Drawing       "Visio.Drawing" 
Word Document       "Word.Document" 
2.  HRESULT Open([in] VARIANT Document, [in, optional] VARIANT ReadOnly, 
[in, optional] VARIANT ProgId, [in, optional] VARIANT WebUsername, [in, optional] VARIANT WebPassword)
    打開文檔,可以是本地文件或者是服務器文件
參數:
 Document  文檔路徑
 ReadOnly  是否已只讀模式打開
 ProgId    OLE類型
 WebUsername  用戶名(訪問網絡的文件時候,有可能需要)
 WebPassword  密碼
例子:
DsoFramer1.Open "C:\TestBook.xls"
DsoFramer1.Open "C:\Plain.txt", , "Word.Document"  //用Word來打開c:\plain.txt文件
DsoFramer1.Open "https://secureserver/test/mytest.asp?id=123", True, "Excel.Sheet", "MyUserAccount", "MyPassword"

3.HRESULT Save([in, optional] VARIANT SaveAsDocument, [in, optional] VARIANT OverwriteExisting, 
                [in, optional] VARIANT WebUsername, [in, optional] VARIANT WebPassword);
保存文件在本地
 DsoFramer1.Save "c:\1.doc"
 
4.Activate
激活當前文檔,沒搞明白有什麼用
5.  HRESULT ActiveDocument([out,retval] IDispatch** ppdisp);
返回當前活動文檔的Dispatch接口,這個接口很重要,可以通過這個接口,操作所有的文檔接口。
如:下面 javascript 語句調用Office內置的對話框
var obj;
obj = new Object(document.all.FramerControl1.ActiveDocument);
if(obj !=null){
 var dd;
 dd = obj.Application.Dialogs(84).Show();
 //... ... 
 //delete it
 delete obj;
}
6.  HRESULT Close();
關閉當前文檔,建議在頁面關閉的時候調用。
MS的原來的版本,有時候關不掉Word,已經修復了。
7.  HRESULT Caption([out,retval] BSTR* pbstr);
屬性,獲取|設置窗口標題
8.  HRESULT Titlebar([in] boolean vbool);
   HRESULT Titlebar([out,retval] boolean* pbool);
   顯示或者隱藏標題欄
9. HRESULT Toolbars([in] boolean vbool);
  HRESULT Toolbars([out,retval] boolean* pbool);
   顯示或者隱藏工具欄
10.  HRESULT ModalState([in] boolean vbool);
   HRESULT ModalState([out,retval] boolean* pbool);

11.HRESULT ShowDialog([in] dsoShowDialogType DlgType);
  顯示對話框
12.HRESULT EnableFileCommand([in] dsoFileCommandType Item, [in] boolean vbool);
  HRESULT EnableFileCommand([in] dsoFileCommandType Item, [out,retval] boolean* pbool);


13.  HRESULT BorderStyle([in] dsoBorderStyle style);
  HRESULT BorderStyle([out, retval] dsoBorderStyle* pstyle);

14.  HRESULT BorderColor([in] OLE_COLOR clr);
  HRESULT BorderColor([out,retval] OLE_COLOR* pclr);

15. HRESULT BackColor([in] OLE_COLOR clr);
  HRESULT BackColor([out,retval] OLE_COLOR* pclr);

16.HRESULT ForeColor([in]OLE_COLOR clr);
  HRESULT ForeColor([out,retval]OLE_COLOR* pclr);

17.HRESULT TitlebarColor([in] OLE_COLOR clr);
 HRESULT TitlebarColor([out,retval] OLE_COLOR* pclr);

18.HRESULT TitlebarTextColor([in] OLE_COLOR clr);
   HRESULT TitlebarTextColor([out,retval] OLE_COLOR* pclr);

19.HRESULT ExecOleCommand([in] LONG OLECMDID, [in, optional] VARIANT Options, [in, optional] VARIANT* vInParam, [in, out, optional] VARIANT* vInOutParam);

20.HRESULT Menubar([in] boolean vbool);
  HRESULT Menubar([out,retval] boolean* pbool);
21.HRESULT HostName([in] BSTR bstr);
  HRESULT HostName([out,retval] BSTR* pbstr);
  
22. HRESULT DocumentFullName([out,retval] BSTR* pbstr);
   文檔的路徑
23.HRESULT PrintOut([in, optional] VARIANT PromptUser, [in, optional] VARIANT PrinterName, [in, optional] VARIANT Copies,
    [in, optional] VARIANT FromPage, [in, optional] VARIANT ToPage, [in, optional] VARIANT OutputFile);
24.HRESULT PrintPreview();
   
25.HRESULT PrintPreviewExit();
26.HRESULT IsReadOnly([out,retval] boolean* pbool);
   是否爲只讀的。
27.HRESULT IsDirty([out,retval] boolean* pbool);
   是否保存了,實際可以用來判讀文檔有沒有修改
   oframer.IsDirty = TRUE //文檔沒有保存,處於修改狀態
    oframer.IsDirty = FALSE //文檔已經保存,沒有修改


發佈了32 篇原創文章 · 獲贊 6 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章