Dso Framer1

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 //文档已经保存,没有修改

新加的接口说明(开发接口)

[color=red][b]当前版本:V 2.2.0.8   2007-02-07[/b]

[/color]下载控件需要登录

说明:

控件未经大批量测试,难免有Bug,

发现 Bug,请及时发帖或者Mail:[email protected]

版本修改记录:

V2.2.0.8修改:

                增加了N多个事件,挺不错的东西

                [id(DSOF_DISPID_WORD_DocumentChange), helpstring("DSOF_DISPID_WORD_DocumentChange")]

                HRESULT WORD_DocumentChange();

                [id(DSOF_DISPID_WORD_DocumentBeforePrint), helpstring("DSOF_DISPID_WORD_DocumentBeforePrint")]

                HRESULT WORD_DocumentBeforePrint();

                [id(DSOF_DISPID_WORD_WindowActivate), helpstring("DSOF_DISPID_WORD_WindowActivate")]

                HRESULT WORD_WindowActivate();

                [id(DSOF_DISPID_WORD_WindowSelectionChange), helpstring("DSOF_DISPID_WORD_WindowSelectionChange")]

                HRESULT WORD_WindowSelectionChange();

                [id(DSOF_DISPID_WORD_WindowBeforeRightClick), helpstring("DSOF_DISPID_WORD_WindowBeforeRightClick")]

                HRESULT WORD_WindowBeforeRightClick();

                [id(DSOF_DISPID_WORD_WindowBeforeDoubleClick), helpstring("DSOF_DISPID_WORD_WindowBeforeDoubleClick")]

                HRESULT WORD_WindowBeforeDoubleClick();

V2.2.0.6修改:

                修改Open,参数为空时候,一个小 Bug

                修改了URL过长时候一个Bug

                增加了一个替换文字的接口

                long ReplaceText(BSTR strSearchText, BSTR strReplaceText,  long lGradation);

V2.2.0.2修改:

                修改了HttpPost相对路径的一些问题。   

V2.2.0.0增加:

                [id(0x00010041), helpstring("Get Rev Index")]

                HRESULT GetRevCount( [out,retval] long * pbool);

                [id(0x00010042), helpstring("Get Rev Index Info")]

                HRESULT GetRevInfo([in] long lIndex, [in]  long lType, [out,retval] BSTR* pbool);

                [id(0x00010043), helpstring("Set Doc Prop")]

                HRESULT SetValue([in] BSTR strValue, [in]  BSTR strName, [out,retval] long* pbool);

                [id(0x00010044), helpstring("Set Doc Variable")]

                HRESULT SetDocVariable([in] BSTR strVarName, [in]  BSTR strValue,[in] long lOpt, [out,retval] long* pbool);

                [id(0x00010045), helpstring("Save page To Doc")]

                HRESULT SetPageAs([in] BSTR strLocalFile, [in]  long lPageNum, [in]  long lType,[out,retval] long* pbool);

--------------------------------------------------------------------------------------------------------------------------------------------------------------------

LoadDso.js

var s = ""

s += "<OBJECT id=DSOFramer align='middle' style='LEFT: 0px; WIDTH: 100%; TOP: 0px; HEIGHT: 100%'"

s += "classid=clsid:00460182-9E5E-11D5-B7C8-B8269041DD57 codeBase=DSOFramer.ocx#Version=2,2,0,6' >"

s += "</OBJECT>"

document.write(s)

接口文档:

 

//新建Word

document.all.FramerControl1.CreateNew("Word.Document");

//新建Excel

document.all.FramerControl1.CreateNew("Excel.Sheet");

 

//打开制定的本地文件

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);

 

//到本地

document.all.FramerControl1.Save("c:\\1.doc",true);

//服务器   

 

//初始化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");

 

//进入留痕状态

document.all.FramerControl1.SetTrackRevisions(1);

//进入非留痕状态

document.all.FramerControl1.SetTrackRevisions(0);

//接受当前修订

document.all.FramerControl1.SetTrackRevisions(4);

 

document.all.FramerControl1.SetCurrUserName("张三");        

 

document.all.FramerControl1.SetCurrTime("2006:02:07 11:11:11");

 

//在当前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::");

 

//只有新建菜单可用

document.all.FramerControl1..SetMenuDisplay(1);

//只有打开菜单可用

document.all.FramerControl1.SetMenuDisplay(2);

//只有打开新建菜单可用

document.all.FramerControl1.SetMenuDisplay(3);

 

//完全保护文档,密码为"pwd"   

document.all.FramerControl1.ProtectDoc(1,1,"pwd");

//解除文档保护                 

document.all.FramerControl1.ProtectDoc(0,1,"pwd");

 

//显示修订留痕

document.all.FramerControl1.ShowRevisions(1);

//隐藏修订留痕

document.all.FramerControl1.ShowRevisions(0);

 

//文件头部插入文件

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);

 

               

 

 

//大纲模式

document.all.FramerControl1.ShowView(5);

 

 

 

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));

}

 

//设置文件只读密码

document.all.FramerControl1.SetValue("password","::DOCPROP:PassWord");

//设置文件修改密码

document.all.FramerControl1.SetValue("password","::DOCPROP:WritePW");

 

 

DSO上传服务器原理

Dsoframer1控件采用文件Http上传接口实现文件和表单域的上传保存。

1. 原理

因为Web页面上的Dsoframer1打开的文件无法随表单记录提交到处理页面,所以我们把文件模拟成表单的文件域<input type=file …>,通过接口把文件和表单元素发送到保存记录的页面(过程类似表单的提交)。

2. 主要上传接口:

HttpInit();

该方法用于初始化上传接口,不需要设置参数

HttpAddPostString(String FieldName, String someValue);

添加要提交的表单域, FieldName是要上传表单域名称,someValue是表单域值

例一:

HttpAddPostString("username", "zhangSan");

它类似域表单域的

<input type=text name=username value=zhangSan>

  例二:

   HttpAddPostString("username", WebForm.username.value);

   ….

   <form name= WebForm >

<input type=text name=username value=zhangSan>

   </form>

注意:如果使用上传接口,那么form表单里的表单域不会被提交到处理页面。需要手工添加到上传接口(HttpAddPostString接口),然后通过控件发送到处理页面。例二使用了“WebForm.username.value”获取表单域值。

HttpAddPostCurrFile(String fileName, String ReName);

添加当前Dsoframer1编辑的文件给上传接口,该接口把文件模拟到成一个表单的文件域,并提交到处理页面。

例一:

HttpAddPostCurrFile("File", "");

该接口模拟表单文件域如下:

<input type=file name=File >

注意:第二个参数为空表示控件自动为文件命名,如:temp.doc,如果需要重命名可以在第二个参数指明文件名称,也可在保存页面指定文件名称。

HttpPost(String url);

执行上传操作将文件和表单域提交到url的页面进行保存操作,并获取url页面返回的执行结果 (是否成功,可以根据这个结果来获取服务器端执行的结果)。

url支持绝对路径和相对路径。

绝对路径,例如:[url=http://192.168.0.1/savedoc.asp]http://192.168.0.1/savedoc.asp[/url]

相对路径要以“./”或者“../”开头。例如:./savedoc.asp

3. 完整的上传接口演示

function SaveDoc() {

var returnValue;     // 保存页面的返回值

document.all.Dsoframer11.HttpInit(); // 初始化Http引擎

// 添加相应的Post元素

document.all.Dsoframer11.HttpAddPostString("username", WebForm. username.value);

// 添加上传文件

document.all.Dsoframer11.HttpAddPostCurrFile("File ","");

// 提交上传文件

returnValue = document.all.Dsoframer11.HttpPost("../saveDoc.jsp");

if("true" == returnValue){

  alert("文件上传成功");

} else  {

  alert("文件上传失败")

}

}

4. 关于保存

Dsoframer1上传接口将数据流以Http方式提交到保存页面,至于对数据处理就和普通的文件上传处理一样了.

发布了32 篇原创文章 · 获赞 6 · 访问量 4万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章