dsoFrame.ocx的使用
dsoFrame.ocx的使用?
在页面中引入以下代码:
?
?
<object classid="clsid:00460182-9E5E-11d5-B7C8-B8269041DD57" codeBase="dsoframer.ocx#version=2,2,1,2" id="oframe" width="100%" height="100%"> <param name="BorderStyle" value="1"> <param name="TitlebarColor" value="52479"> <param name="Titlebar" value="0"> <param name="TitlebarTextColor" value="0"> <param name="Menubar" value="1"> <param name="Toolbars" value="1"></object>?
?
1、打开一个doc文件
- 打开本地C盘下的一个33.doc的文件
document.all.DSOFramer1.Open("C:/33.doc",false, "Word.Document");?
?
- 打开远程的word文件
document.all.DSOFramer1.Open("http://localhost:8080/XxShhCtrl-getAttachmentById.pfv?fjxh=xxfbfj000562",true, "Word.Document","MyUserAccount","MyPassword");?
?
- 打开本地的excel文件
document.all.DSOFramer1.Open("C:/11.xls",false, "Excel.Sheet");?2、保存文件到本地
注意:这里的文件指的是把控件中展示的doc文件,以22.doc的名称保存到c盘。
?
?
document.all.DSOFramer1.Save("c:/22.doc");??
?3、保存文件的服务器
function fileUpload(){ //document.all.DSOFramer1.style.display="none"; alert('------'); //初始化Http引擎 document.all.DSOFramer1.HttpInit(); //增加Post变量 //document.all.DSOFramer1.HttpAddPostString("RecordID","20060102200"); document.all.DSOFramer1.HttpAddPostString("userid","mrli"); //上传打开的文件 document.all.DSOFramer1.HttpAddPostCurrFile("file1", "11.doc"); //执行上传动作 document.all.DSOFramer1.HttpPost("http://192.168.0.55:8082/WordCtrl-test1.pfv"); }?
说明:其中userid相当于表单的name,可以通过这个名字,接收到后面的mrli值。而11.doc表示被上传的文件名字。
?
?
4、删除书签
function cleanMark(){ //删除书签 //document.all.DSOFramer1.SetFieldValue("book1","","::ADDMARK::"); document.all.DSOFramer1.SetFieldValue("book1","","::DELMARK::");}??
5、循环打印(适用于人名章问题)
?
function printStamp(){ insToTif(); //插入传真件 for(i=0;i<2;i++){ cleanMark(); //书签内容清除 if(i==0){ document.all.DSOFramer1.SetFieldValue("book1","张三","::ADDMARK::"); }else{ document.all.DSOFramer1.SetFieldValue("book1","李四","::ADDMARK::"); } document.all.DSOFramer1.printout(); }}function cleanMark(){ //删除书签 //document.all.DSOFramer1.SetFieldValue("book1","","::ADDMARK::"); document.all.DSOFramer1.SetFieldValue("book1","","::DELMARK::");}?
?
6、插入传真件
function insToTif(){ //传真件问题 document.all.DSOFramer1.Open("C:/44_2.doc",false, "Word.Document"); //document.all.DSOFramer1.SetFieldValue("book1","c:/cebTest.TIF","::JPG::"); //书签中插入图片 //document.all.DSOFramer1.InsertFile("http://www.google.cn/intl/zh-CN/images/logo_cn.gif",8); //在当前光标处插入图片 document.all.DSOFramer1.InsertFile("c:/cebTest.TIF",8);}?
?
7、书签中插入内容
向名称为book1的书签中插入数据
document.all.DSOFramer1.SetFieldValue("book1","test",""); //向书签book1中插入文字function insToMark(){ document.all.DSOFramer1.SetFieldValue("book1","test","::ADDMARK::"); //新建书签book1,并向其中插入文字 //document.all.DSOFramer1.SetFieldValue("book1","http://localhost:8080/XxShhCtrl-getAttachmentById.pfv?fjxh=xxfbfj000562","::FILE::"); //插入远程图片 //document.all.DSOFramer1.SetFieldValue("book1","c:/33.doc","::FILE::"); //书签中插入本地图片}?
?
8、书签中内容的换行
书签中加入?\r?即可
?
var dd = "testsss\r\r"; document.all.DSOFramer1.SetFieldValue("book1",dd,""); //书签中插入文字 for(i=0;i<10;i++){ document.all.DSOFramer1.SetFieldValue("book1",dd,"::ADDMARK::"); }?
?
9、获取书签中的内容
?
function getBookMark(){ var docObj = document.all.DSOFramer1.ActiveDocument; //获取word对象 var value_bookmark = docObj .bookmarks("book1").Range; //获取书签“book1”中的内容 alert(value_bookmark);}?
?
10、隐藏工具栏
//隐藏菜单
function hidBtn(){ var tt = document.all.DSOFramer1.ActiveDocument; tt.CommandBars(1).Visible=false; tt.CommandBars(2).Visible=false; tt.CommandBars(3).Visible=false; tt.CommandBars(4).Visible=false; tt.CommandBars(5).Visible=false; tt.CommandBars(6).Visible=false; tt.CommandBars(7).Visible=false;}?如果让某一工具栏的某些按钮隐藏,可以用下面的方法
?
??? tt.CommandBars(1).Controls(1).Visible=false; //常用工具栏的第一个图标隐藏
??? tt.CommandBars(1).Controls(3).Visible=false; //常用工具栏的第二个图标隐藏
??? tt.CommandBars(1).Controls(1).Visible=false; //常用工具栏的第三个图标隐藏
?
11、隐藏标题栏,菜单栏,工具栏
document.all.DSOFramer1.Toolbars = false;document.all.DSOFramer1.Menubar = false;document.all.DSOFramer1.Titlebar = false;
?
?
12、视图切换
?
设置文档显示模式HRESULT ShowView(long dwViewType, [out,retval] long * pbool); dwViewType的可取值为:enum WdViewType{ wdNormalView = 1, wdOutlineView = 2, wdPrintView = 3, wdPrintPreview = 4, wdMasterView = 5, //这个是大纲 wdWebView = 6};//如大纲模式document.all.DSOFramer1.ShowView(5);?
?
13、设置表格边框隐藏和显示
?
?
var docObj = document.all.DSOFramer1.ActiveDocument; //获取word对象docObj.Tables(5). Borders.Enable=true;//设置word中第5个表格边框显示docObj.Tables(5). Borders.Enable=false;//设置word中第5个表格边框隐藏docObj.Shapes(2).TextFrame.TextRange.Tables(1). Borders.Enable=true;//设置word中第2个文框中第1个表格显示docObj.Shapes(2).TextFrame.TextRange.Tables(1). Borders.Enable=false;//设置word中第2个文框中第1个表格隐藏?
?
注意:所有控件计数从1开始
?