WebOffice.js 30.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800
/*
form表单名称:webform
iWebOffice名称:WebOffice
WebObject文档对象接口,相当于:
如果是Word  文件,WebObject 是Word  VBA的ActiveDocument对象
如果是Excel 文件,WebObject 是Excel VBA的ActiveSheet对象

如:WebOffice.WebObject
*/

// vardocument.getElementById("WebOffice") = document.getElementById("WebOffice");
//作用:显示操作状态
function StatusMsg(mString){
  // StatusBar.value=mString;
}


//作用:退出iWebOffice
function UnLoad(){
  try{
    if (!WebOffice.WebClose()){
      StatusMsg(WebOffice.Status);
    }
    else{
      StatusMsg("关闭文档...");
    }
  }
  catch(e){
    alert(e.description);
  }
}

//作用:打开文档
function LoadDocument(){
  StatusMsg("正在打开文档...");
  if (!WebOffice.WebOpen()){  	//打开该文档    交互OfficeServer的OPTION="LOADFILE"
    StatusMsg(WebOffice.Status);
  }
  else{
    StatusMsg(WebOffice.Status);
  }
}

//作用:保存文档
function SaveDocument(){
	if(window.__FileType){
		document.getElementById("WebOffice").FileType = window.__FileType;
	}

  //WebOffice.WebSetMsgByName("MyDefine1","自定义变量值1");  //设置变量MyDefine1="自定义变量值1",变量可以设置多个  在WebSave()时,一起提交到OfficeServer中
  document.getElementById("WebOffice").WebSetMsgByName("SAVETYPE",document.getElementById("WebOffice").SAVETYPE);
  if (!WebOffice.WebSave()){    //交互OfficeServer的OPTION="SAVEFILE"  注:WebSave()是保存复合格式文件,包括OFFICE内容和手写批注文档;如只保存成OFFICE文档格式,那么就设WebSave(true)
    StatusMsg(WebOffice.Status);
    return {off_status : 0,off_msg : WebOffice.Status};
  }
  else{
    StatusMsg(WebOffice.Status);
    return {
    	off_status : 1,
    	off_docid : WebOffice.WebGetMsgByName("CREATEID"),
    	off_versionid : WebOffice.WebGetMsgByName("VERSIONID"),
		off_imagefileid : WebOffice.WebGetMsgByName("IMAGEFILEID"),
    };
  }
}


//作用:显示或隐藏痕迹[隐藏痕迹时修改文档没有痕迹保留]  true表示隐藏痕迹  false表示显示痕迹
function ShowRevision(mValue){
  if (mValue){
   document.getElementById("WebOffice").WebShow(true);
    StatusMsg("显示痕迹...");
  }
  else{
   document.getElementById("WebOffice").WebShow(false);
    StatusMsg("隐藏痕迹...");
  }
}


//作用:显示或隐藏痕迹[隐藏痕迹时修改文档有痕迹保留]  true表示隐藏痕迹  false表示显示痕迹
function ShowRevision2(mValue){
  if (mValue){
   document.getElementById("WebOffice").WebObject.ShowRevisions=true;   //显示痕迹
  }
  else{
   document.getElementById("WebOffice").WebObject.ShowRevisions=false;  //隐藏痕迹
  }
}


//作用:获取痕迹
function WebGetRevisions(){
  var Rev =document.getElementById("WebOffice").WebObject.Revisions;		//获取痕迹对象
  var Text="";

  for (i = 1;i <= Rev.Count;i++){
    Text=Text +"“"+ Rev.Item(i).Author+"”";
    if (Rev.Item(i).Type=="1"){
      Text=Text + '进行插入:'+Rev.Item(i).Range.Text+"\r\n";
    }else if (Rev.Item(i).Type=="2"){
      Text=Text + '进行删除:'+Rev.Item(i).Range.Text+"\r\n";
    }
	else {
      Text=Text + '进行其他操作,操作内容:“'+Rev.Item(i).Range.Text+ '”;操作:“'+Rev.Item(i).FormatDescription+"”。\r\n";
    }
  }
  alert("痕迹内容:\r\n\r\n"+Text);
}

//作用:刷新文档
function WebReFresh(){
 document.getElementById("WebOffice").WebReFresh();
  StatusMsg("文档已刷新...");
}


//作用:打开版本
function WebOpenVersion(){
 document.getElementById("WebOffice").WebOpenVersion();  	//交互OfficeServer  列出版本OPTION="LISTVERSION"     调出版本OPTION="LOADVERSION"   <参考技术文档>
  StatusMsg(WebOffice.Status);
}

//作用:保存版本
function WebSaveVersion(){
 document.getElementById("WebOffice").WebSaveVersion();  	//交互OfficeServer的OPTION="SAVEVERSION"
  StatusMsg(WebOffice.Status);
}

//作用:保存当前版本
function WebSaveVersionByFileID(){
  var mText=window.prompt("请输入版本说明:","版本号:V");
  if (mText==null){
    mText="已修改版本.";
  }
 document.getElementById("WebOffice").WebSaveVersionByFileID(mText);  	//交互OfficeServer的OPTION="SAVEVERSION"  同时带FileID值   <参考技术文档>
  StatusMsg(WebOffice.Status);
}


//作用:填充模板
function LoadBookmarks(){
  StatusMsg("正在填充模扳...");
  if (!WebOffice.WebLoadBookmarks()){  	//交互OfficeServer的OPTION="LOADBOOKMARKS"
    StatusMsg(WebOffice.Status);
  }else{
    StatusMsg(WebOffice.Status);
  }
}

//作用:标签管理
function WebOpenBookMarks(){
  try{
   document.getElementById("WebOffice").WebOpenBookmarks();  	//交互OfficeServer的OPTION="LISTBOOKMARKS"
    StatusMsg(WebOffice.Status);
  }
  catch(e){
    alert(e.description);
  }
}

//作用:设置书签值  vbmName:标签名称,vbmValue:标签值   标签名称注意大小写
function SetBookmarks(vbmName,vbmValue){
  if(WebOffice.FileType!=".doc"){return false;}
  if (!WebOffice.WebSetBookmarks(vbmName,vbmValue)){
    StatusMsg(WebOffice.Status);
  }else{
    StatusMsg(WebOffice.Status);
  }
}

//作用:根据标签名称获取标签值  vbmName:标签名称
function GetBookmarks(vbmName){
  var vbmValue;
  vbmValue=WebOffice.WebGetBookmarks(vbmName);
  return vbmValue;
}

//作用:打印文档
function WebOpenPrint(){
  try{
   document.getElementById("WebOffice").WebOpenPrint();
    StatusMsg(WebOffice.Status);
  }
  catch(e){
    alert(e.description);
  }
}


//作用:页面设置
function WebOpenPageSetup(){
  try{
    if (WebOffice.FileType==".doc"){
	 document.getElementById("WebOffice").WebObject.Application.Dialogs(178).Show();
	}
	if(WebOffice.FileType==".xls"){
	 document.getElementById("WebOffice").WebObject.Application.Dialogs(7).Show();
	}
  }
  catch(e){
    alert(e.description);
  }
}

//作用:插入图片
function WebOpenPicture(){
  try{
   document.getElementById("WebOffice").WebOpenPicture();
    StatusMsg(WebOffice.Status);
  }
  catch(e){
    alert(e.description);
  }
}

//作用:签名印章
function WebOpenSignature(){
  alert("如果你要更安全签章,建议采用金格iSignature电子签章软件进行签章:\r\n下载地址http://www.goldgrid.cn/iSignature/Download.asp\r\n\r\n该软件是支持文档完整性保护、CA证书和数字签名技术的,\r\n是通过了<国家公安部和国家保密局>双重认证的安全电子签章产品!");
  try{
   document.getElementById("WebOffice").WebOpenSignature();  	//交互OfficeServer的 A签章列表OPTION="LOADMARKLIST"    B签章调出OPTION="LOADMARKIMAGE"    C确定签章OPTION="SAVESIGNATURE"    <参考技术文档>
    StatusMsg(WebOffice.Status);
  }
  catch(e){
    alert(e.description);
  }
}

//作用:验证印章A
function WebShowSignature(){
  try{
   document.getElementById("WebOffice").WebShowSignature();  	//交互OfficeServer的OPTION="LOADSIGNATURE"
    StatusMsg(WebOffice.Status);
  }
  catch(e){
    alert(e.description);
  }
}

//作用:验证印章B
function WebCheckSignature(){
  try{
    var i=WebOffice.WebCheckSignature();  	//交互OfficeServer的OPTION="LOADSIGNATURE"
    alert("检测结果:"+i+"\r\n 注释: (=-1 有非法印章) (=0 没有任何印章) (>=1 有多个合法印章)");
    StatusMsg(i);
  }
  catch(e){
    alert(e.description);
  }
}

//作用:存为本地文件
function WebSaveLocal(){
  try{
   document.getElementById("WebOffice").WebSaveLocal();
    StatusMsg(WebOffice.Status);
  }
  catch(e){
    alert(e.description);
  }
}

//作用:打开本地文件
function WebOpenLocal(){
  try{
   document.getElementById("WebOffice").WebOpenLocal();
    StatusMsg(WebOffice.Status);
  }
  catch(e){
    alert(e.description);
  }
}



//作用:关闭或显示工具 参数1表示工具条名称  参数2为false时,表示关闭  (名称均可查找VBA帮助)
//参数2为true时,表示显示
function WebToolsVisible(ToolName,Visible){
  try{
   document.getElementById("WebOffice").WebToolsVisible(ToolName,Visible);
    StatusMsg(WebOffice.Status);
  }
  catch(e){
    alert(e.description);
  }
}


//作用:禁止或启用工具 参数1表示工具条名称  参数2表示工具条铵钮的编号  (名称和编号均可查找VBA帮助)
//参数3为false时,表示禁止  参数3为true时,表示启用
function WebToolsEnable(ToolName,ToolIndex,Enable){
  try{
   document.getElementById("WebOffice").WebToolsEnable(ToolName,ToolIndex,Enable);
    StatusMsg(WebOffice.Status);
  }
  catch(e){
    alert(e.description);
  }
}

//作用:保护与解除  参数1为true表示保护文档  false表示解除保护
function WebProtect(value){
  try{
   document.getElementById("WebOffice").WebSetProtect(value,"");  //""表示密码为空
  }
  catch(e){
    alert(e.description);
  }
}

//作用:允许与禁止拷贝功能  参数1为true表示允许拷贝  false表示禁止拷贝
function WebEnableCopy(value){
  try{
   document.getElementById("WebOffice").CopyType=value;
  }
  catch(e){
    alert(e.description);
  }
}


//作用:插入远程服务器图片
function WebInsertImage(){
  try{
   document.getElementById("WebOffice").WebInsertImage('Image','GoldgridLogo.jpg',true,4);   //交互OfficeServer的OPTION="INSERTIMAGE"  参数1表示标签名称  参数2表示图片文件名  参数3为true透明  false表示不透明  参数4为4表示浮于文字上方  5表示衬于文字下方
    StatusMsg(WebOffice.Status);
  }
  catch(e){
    alert(e.description);
  }
}


//作用:下载服务器文件到本地
function WebGetFile(){
  if (WebOffice.WebGetFile("c:\\WebGetFile.doc","DownLoad.doc")){   //交互OfficeServer的OPTION="GETFILE"  参数1表示本地路径  参数2表示服务器文件名称
    StatusMsg(WebOffice.Status);
  }else{
    StatusMsg(WebOffice.Status);
  }
  alert(WebOffice.Status+"\r\n"+"文件放在c:\\WebGetFile.doc");
}


//作用:上传本地文件到服务器
function WebPutFile(){
  var mLocalFile=WebOffice.WebOpenLocalDialog();
  if (mLocalFile!=""){
    alert(mLocalFile);
    if (WebOffice.WebPutFile(mLocalFile,"Test.doc")){   //交互OfficeServer的OPTION="PUTFILE"  参数1表示本地路径,可以任何格式文件  参数2表示服务器文件名称
      StatusMsg(WebOffice.Status);
    }else{
      StatusMsg(WebOffice.Status);
    }
    alert(WebOffice.Status);
  }
}


//作用:打开远程文件
function WebDownLoadFile(){
  mResult=WebOffice.WebDownLoadFile("http://www.goldgrid.com/Images/abc.doc","c:\\abc.doc");
  if (mResult){
   document.getElementById("WebOffice").WebOpenLocalFile("c:\\abc.doc");
    alert("成功");
  }else{
    alert("失败");
  }
}

//作用:取得服务器端时间,设置本地时间  [V6.0.1.5以上支持]
function WebDateTime(){
  mResult=WebOffice.WebDateTime(true);   //交互OfficeServer的OPTION="DATETIME"   true表示返回并设置本地时间为服务器时间;false表示仅返回服务器时间
  alert("提示:已经设置本地时间为 "+mResult);    //该功能主要用于在痕迹保留时读取服务器时间
}


//作用:表格生成及填充
function WebSetWordTable(){
  var mText="",mName="",iColumns,iCells,iTable;
  //设置COMMAND为WORDTABLE
 document.getElementById("WebOffice").WebSetMsgByName("COMMAND","WORDTABLE");   //设置变量COMMAND="WORDTABLE",在WebSendMessage()时,一起提交到OfficeServer中
  //发送到服务器上
  //如果没有错误
  if (WebOffice.WebSendMessage()){                //交互OfficeServer的OPTION="SENDMESSAGE"
	iColumns =document.getElementById("WebOffice").WebGetMsgByName("COLUMNS");  //取得列
	iCells =document.getElementById("WebOffice").WebGetMsgByName("CELLS");      //取得行
	iTable=WebOffice.WebObject.Tables.Add(WebOffice.WebObject.Application.Selection.Range,iCells,iColumns);   //生成表格
	for (var i=1; i<=iColumns; i++){
   	  for (var j=1; j<=iCells; j++){
		mName=i.toString()+j.toString();
		mText=WebOffice.WebGetMsgByName(mName);	 //取得OfficeServer中的表格内容
		iTable.Columns(i).Cells(j).Range.Text=mText;   	//填充单元值
	  }
	}
  }
  StatusMsg(WebOffice.Status);
}


//作用:获取文档Txt正文
function WebGetWordContent(){
  try{
    alert(WebOffice.WebObject.Content.Text);
  }
  catch(e){
    alert(e.description);
  }
}

//作用:写Word内容
function WebSetWordContent(){
  var mText=window.prompt("请输入内容:","测试内容");
  if (mText==null){
    return false;
  }
  else{
    //下面为显示选中的文本
    //alert(WebOffice.WebObject.Application.Selection.Range.Text);
    //下面为在当前光标出插入文本
   document.getElementById("WebOffice").WebObject.Application.Selection.Range.Text= mText+"\n";
    //下面为在第一段后插入文本
    //WebOffice.WebObject.Application.ActiveDocument.Range(1).Text=(mText);
  }
}


//作用:打印黑白文档
function WebWordPrintBlackAndWhile(){
   var i,n;

   //图片变黑白
   i=0;
   n=WebOffice.WebObject.Shapes.Count;
   for (var i=1; i<=n; i++){
    document.getElementById("WebOffice").WebObject.Shapes.Item(i).PictureFormat.ColorType=3;
   }
   i=0;
   n=WebOffice.WebObject.InlineShapes.Count;
   for (var i=1; i<=n; i++){
    document.getElementById("WebOffice").WebObject.InlineShapes.Item(i).PictureFormat.ColorType=3;
   }

   //文字变黑白
  document.getElementById("WebOffice").WebObject.Application.Selection.WholeStory();
  document.getElementById("WebOffice").WebObject.Application.Selection.Range.Font.Color = 0;
}

//作用:用Excel求和
function WebGetExcelContent(){
 document.getElementById("WebOffice").WebObject.Application.Sheets(1).Select();
 document.getElementById("WebOffice").WebObject.Application.Range("C5").Select();
 document.getElementById("WebOffice").WebObject.Application.ActiveCell.FormulaR1C1 = "126";
 document.getElementById("WebOffice").WebObject.Application.Range("C6").Select();
 document.getElementById("WebOffice").WebObject.Application.ActiveCell.FormulaR1C1 = "446";
 document.getElementById("WebOffice").WebObject.Application.Range("C7").Select();
 document.getElementById("WebOffice").WebObject.Application.ActiveCell.FormulaR1C1 = "556";
 document.getElementById("WebOffice").WebObject.Application.Range("C5:C8").Select();
 document.getElementById("WebOffice").WebObject.Application.Range("C8").Activate;
 document.getElementById("WebOffice").WebObject.Application.ActiveCell.FormulaR1C1 = "=SUM(R[-3]C:R[-1]C)";
 document.getElementById("WebOffice").WebObject.Application.Range("D8").Select();
  alert(WebOffice.WebObject.Application.Range("C8").Text);
}


//作用:保护工作表单元
function WebSheetsLock(){
 document.getElementById("WebOffice").WebObject.Application.Sheets(1).Select();

 document.getElementById("WebOffice").WebObject.Application.Range("A1").Select();
 document.getElementById("WebOffice").WebObject.Application.ActiveCell.FormulaR1C1 = "产品";
 document.getElementById("WebOffice").WebObject.Application.Range("B1").Select();
 document.getElementById("WebOffice").WebObject.Application.ActiveCell.FormulaR1C1 = "价格";
 document.getElementById("WebOffice").WebObject.Application.Range("C1").Select();
 document.getElementById("WebOffice").WebObject.Application.ActiveCell.FormulaR1C1 = "详细说明";
 document.getElementById("WebOffice").WebObject.Application.Range("D1").Select();
 document.getElementById("WebOffice").WebObject.Application.ActiveCell.FormulaR1C1 = "库存";
 document.getElementById("WebOffice").WebObject.Application.Range("A2").Select();
 document.getElementById("WebOffice").WebObject.Application.ActiveCell.FormulaR1C1 = "书签";
 document.getElementById("WebOffice").WebObject.Application.Range("A3").Select();
 document.getElementById("WebOffice").WebObject.Application.ActiveCell.FormulaR1C1 = "毛笔";
 document.getElementById("WebOffice").WebObject.Application.Range("A4").Select();
 document.getElementById("WebOffice").WebObject.Application.ActiveCell.FormulaR1C1 = "钢笔";
 document.getElementById("WebOffice").WebObject.Application.Range("A5").Select();
 document.getElementById("WebOffice").WebObject.Application.ActiveCell.FormulaR1C1 = "尺子";

 document.getElementById("WebOffice").WebObject.Application.Range("B2").Select();
 document.getElementById("WebOffice").WebObject.Application.ActiveCell.FormulaR1C1 = "0.5";
 document.getElementById("WebOffice").WebObject.Application.Range("C2").Select();
 document.getElementById("WebOffice").WebObject.Application.ActiveCell.FormulaR1C1 = "樱花";
 document.getElementById("WebOffice").WebObject.Application.Range("D2").Select();
 document.getElementById("WebOffice").WebObject.Application.ActiveCell.FormulaR1C1 = "300";

 document.getElementById("WebOffice").WebObject.Application.Range("B3").Select();
 document.getElementById("WebOffice").WebObject.Application.ActiveCell.FormulaR1C1 = "2";
 document.getElementById("WebOffice").WebObject.Application.Range("C3").Select();
 document.getElementById("WebOffice").WebObject.Application.ActiveCell.FormulaR1C1 = "狼毫";
 document.getElementById("WebOffice").WebObject.Application.Range("D3").Select();
 document.getElementById("WebOffice").WebObject.Application.ActiveCell.FormulaR1C1 = "50";

 document.getElementById("WebOffice").WebObject.Application.Range("B4").Select();
 document.getElementById("WebOffice").WebObject.Application.ActiveCell.FormulaR1C1 = "3";
 document.getElementById("WebOffice").WebObject.Application.Range("C4").Select();
 document.getElementById("WebOffice").WebObject.Application.ActiveCell.FormulaR1C1 = "蓝色";
 document.getElementById("WebOffice").WebObject.Application.Range("D4").Select();
 document.getElementById("WebOffice").WebObject.Application.ActiveCell.FormulaR1C1 = "90";

 document.getElementById("WebOffice").WebObject.Application.Range("B5").Select();
 document.getElementById("WebOffice").WebObject.Application.ActiveCell.FormulaR1C1 = "1";
 document.getElementById("WebOffice").WebObject.Application.Range("C5").Select();
 document.getElementById("WebOffice").WebObject.Application.ActiveCell.FormulaR1C1 = "20cm";
 document.getElementById("WebOffice").WebObject.Application.Range("D5").Select();
 document.getElementById("WebOffice").WebObject.Application.ActiveCell.FormulaR1C1 = "40";

  //保护工作表
 document.getElementById("WebOffice").WebObject.Application.Range("B2:D5").Select();
 document.getElementById("WebOffice").WebObject.Application.Selection.Locked = false;
 document.getElementById("WebOffice").WebObject.Application.Selection.FormulaHidden = false;
 document.getElementById("WebOffice").WebObject.Application.ActiveSheet.Protect(true,true,true);

  alert("已经保护工作表,只有B2-D5单元格可以修改。");
}

//作用:VBA套红
function WebInsertVBA(){
  //画线
  var object=WebOffice.WebObject;
  var myl=object.Shapes.AddLine(100,60,305,60)
  myl.Line.ForeColor=255;
  myl.Line.Weight=2;
  var myl1=object.Shapes.AddLine(326,60,520,60)
  myl1.Line.ForeColor=255;
  myl1.Line.Weight=2;

  //object.Shapes.AddLine(200,200,450,200).Line.ForeColor=6;
  var myRange=WebOffice.WebObject.Range(0,0);
  myRange.Select();

  var mtext="★";
 document.getElementById("WebOffice").WebObject.Application.Selection.Range.InsertAfter (mtext+"\n");
  var myRange=WebOffice.WebObject.Paragraphs(1).Range;
  myRange.ParagraphFormat.LineSpacingRule =1.5;
  myRange.font.ColorIndex=6;
  myRange.ParagraphFormat.Alignment=1;
  myRange=WebOffice.WebObject.Range(0,0);
  myRange.Select();
  mtext="金格发[2012]154号";
 document.getElementById("WebOffice").WebObject.Application.Selection.Range.InsertAfter (mtext+"\n");
  myRange=WebOffice.WebObject.Paragraphs(1).Range;
  myRange.ParagraphFormat.LineSpacingRule =1.5;
  myRange.ParagraphFormat.Alignment=1;
  myRange.font.ColorIndex=1;

  mtext="金格电子政务文件";
 document.getElementById("WebOffice").WebObject.Application.Selection.Range.InsertAfter (mtext+"\n");
  myRange=WebOffice.WebObject.Paragraphs(1).Range;
  myRange.ParagraphFormat.LineSpacingRule =1.5;

  //myRange.Select();
  myRange.Font.ColorIndex=6;
  myRange.Font.Name="仿宋_GB2312";
  myRange.font.Bold=true;
  myRange.Font.Size=50;
  myRange.ParagraphFormat.Alignment=1;

  //myRange=myRange=WebOffice.WebObject.Paragraphs(1).Range;
 document.getElementById("WebOffice").WebObject.PageSetup.LeftMargin=70;
 document.getElementById("WebOffice").WebObject.PageSetup.RightMargin=70;
 document.getElementById("WebOffice").WebObject.PageSetup.TopMargin=70;
 document.getElementById("WebOffice").WebObject.PageSetup.BottomMargin=70;
}

//作用:模版套红功能
function WebUseTemplate(){
  var mDialogUrl = "Template/TemplateForm.htm";
  var mObject = new Object();
  mObject.Template = "";
  window.showModalDialog(mDialogUrl, mObject, "dialogHeight:200px; dialogWidth:360px;center:yes;scroll:no;status:no;");

  //判断用户是否选择模板
  if (mObject.Template==""){
    StatusMsg("取消套用模板");
    return false;
  }else{
    if(WebAcceptAllRevisions()==false){                         //清除正文痕迹的目的是为了避免痕迹状态下出现内容异常问题。
      StatusMsg("清除正文痕迹失败,套红中止");
      return false;      
    }
    SaveDocument();                                             //保存当前编辑的文档
   document.getElementById("WebOffice").WebSetMsgByName("COMMAND","INSERTFILE");  //设置变量COMMAND="INSERTFILE",在WebLoadTemplate()时,一起提交到OfficeServer中     <参考技术文档>
   document.getElementById("WebOffice").Template=mObject.Template;                //全局变量Template赋值,此示例读取服务器目录中模板,如读取数据库中模板,Template值为数据库中的模板编号,则上句代码不需要,如Template="1050560363767",模板名称为“Word公文模板”,注:模板中有要标签Content,区分大小写,可以自行修改
   document.getElementById("WebOffice").EditType="1";                             //控制为不保留痕迹的状态
    if (WebOffice.WebLoadTemplate()){                   //交互OfficeServer的OPTION="LOADTEMPLATE"
      //SetBookmarks("Title","关于中间件研发工作会议通知");     //填充模板其它基本信息,如标题,主题词,文号,主送机关等
      if (WebOffice.WebInsertFile()){                   //填充公文正文   交互OfficeServer的OPTION="INSERTFILE"
        StatusMsg("模板套红成功");
        return true;
      }else{
        StatusMsg(WebOffice.Status);
        return false;
      }
    }else{
      StatusMsg(WebOffice.Status);
      return false;
    }
  }
}

//作用:保存定稿文件
function WebUpdateFile(){
  if (WebOffice.WebUpdateFile()){                //交互OfficeServer的OPTION="UPDATEFILE",类似WebSave()或WebSaveVersion()方法
    StatusMsg(WebOffice.Status);
  }else{
    StatusMsg(WebOffice.Status);
  }
}

//作用:导入Text
function WebInportText(){
  var mText;
 document.getElementById("WebOffice").WebSetMsgByName("COMMAND","INPORTTEXT");  //设置变量COMMAND="INPORTTEXT",在WebSendMessage()时,一起提交到OfficeServer中
  if (WebOffice.WebSendMessage()){                    //交互OfficeServer的OPTION="SENDMESSAGE"
    mText=WebOffice.WebGetMsgByName("CONTENT");       //取得OfficeServer传递的变量CONTENT值
   document.getElementById("WebOffice").WebObject.Application.Selection.Range.Text=mText;
    alert("导入文本成功");
  }
  StatusMsg(WebOffice.Status);
}


//作用:导出Text
function WebExportText(){
  var mText=WebOffice.WebObject.Content.Text;
 document.getElementById("WebOffice").WebSetMsgByName("COMMAND","EXPORTTEXT");  //设置变量COMMAND="EXPORTTEXT",在WebSendMessage()时,一起提交到OfficeServer中
 document.getElementById("WebOffice").WebSetMsgByName("CONTENT",mText);         //设置变量CONTENT="mText",在WebSendMessage()时,一起提交到OfficeServer中,可用于实现全文检索功能,对WORD的TEXT内容进行检索
  if (WebOffice.WebSendMessage()){                    //交互OfficeServer的OPTION="SENDMESSAGE"
    alert("导出文本成功");
  }
  StatusMsg(WebOffice.Status);
}


//作用:获取文档页数
function WebDocumentPageCount(){
  var intPageTotal =document.getElementById("WebOffice").WebObject.Application.ActiveDocument.BuiltInDocumentProperties(14);
  alert("文档页总数:"+intPageTotal);
}

//作用:签章锁定文件功能
function WebSignatureAtReadonly(){
 document.getElementById("WebOffice").WebSetProtect(false,"");                  //解除文档保护
 document.getElementById("WebOffice").WebSetRevision(false,false,false,false);  //设置文档痕迹保留的状态  参数1:不显示痕迹  参数2:不保留痕迹  参数3:不打印时有痕迹  参数4:不显痕迹处理工具
  try{
   document.getElementById("WebOffice").WebOpenSignature();                     //交互OfficeServer的 A签章列表OPTION="LOADMARKLIST"    B签章调出OPTION="LOADMARKIMAGE"    C确定签章OPTION="SAVESIGNATURE"    <参考技术文档>    文档中要定义标签Manager,可以自行修改标签名称
    StatusMsg(WebOffice.Status);
  }
  catch(e){
    alert(e.description);
  }
 document.getElementById("WebOffice").WebSetProtect(true,"");                   //锁定文档
}

//作用:客户端和服务器端信息信息交互
function WebSendInformation(){
  var info = window.prompt("请输入要传到服务器处理页面上的内容:","参数内容");
  if (info==null){return false}

 document.getElementById("WebOffice").WebSetMsgByName("COMMAND","SELFINFO");		//设置变量COMMAND="SELFINFO",用来在服务器端做判断,以进入处理自定义参数传递的代码。
 document.getElementById("WebOffice").WebSetMsgByName("TESTINFO",info);			//自定义的一个参数"TESTINFO",将info变量的信息设置到信息包中,以便传到后台。
  if (WebOffice.WebSendMessage()){						//向后台发信息包。交互OfficeServer的OPTION="SENDMESSAGE"。
    info =document.getElementById("WebOffice").WebGetMsgByName("RETURNINFO");		//如果交互成功,接受服务器端返回的信息。
	alert(info);
  }
  else{
    StatusMsg(WebOffice.Status);
  }
}

//判断编辑器
function GetEditer(){
  if(WebOffice.WebApplication(".doc")){     //WORD
    alert("存在WORD编辑器");
  }
  if(WebOffice.WebApplication(".xls")){     //EXCEL
    alert("存在EXCEL编辑器");
  }
  if(WebOffice.WebApplication(".wps")){     //金山WPS
    alert("存在WPS编辑器");
  }
  if(WebOffice.WebApplication(".et")){      //金山表格
    alert("存在ET编辑器");
  }
  //参数还可以是".ppt"、".vso"......
}

//设置OFFICE2007的选项卡显示
function WebSetRibbonUIXML(){
 document.getElementById("WebOffice").RibbonUIXML = '' +
  '<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">' +
  '  <ribbon startFromScratch="false">'+                    //不显示所有选项卡控制 false显示选项卡;true不显示选项卡
  '    <tabs>'+
  '      <tab idMso="TabReviewWord" visible="false">' +     //关闭视图工具栏
  '      </tab>'+
  '      <tab idMso="TabInsert" visible="false">' +         //关闭插入工具栏
  '      </tab>'+
  '      <tab idMso="TabHome" visible="false">' +           //关闭开始工具栏
  '      </tab>'+
  '    </tabs>' +
  '  </ribbon>' +
  '</customUI>';

/*
    最常用的内置选项卡名称
    选项卡名称      idMso(Excel)      idMso(Word)       idMso(Access)
    开始            TabHome             TabHome             TabHomeAccess
    插入            TabInsert           TabInsert           (none)
    页面布局        TabPageLayoutExcel  TabPageLayoutWord   (none)
    公式            TabFormulas         (none)            (none)
    数据            TabData             (none)            (none)
    视图            TabReview           TabReviewWord       (none)
    创建            (none)            (none)            TabCreate
    外部数据        (none)            (none)            TabExternalData
    数据库工具      (none)            (none)            TabDatabaseTools
*/

/*
    iWebOffice控件的RibbonUIXML属性,是基于OFFICE2007的RibbonX的应用。关于RibbonX的相关资料,需要自己另行查询。
*/
}

//读取注册表(十进制)
function WebReadRegString(){
  try{
   document.getElementById("WebOffice").WebOpenKey('HKEY_CURRENT_USER', 'Software\\Microsoft\\Office\\12.0\\Common\\Toolbars');    //打开注册表
    var Content =document.getElementById("WebOffice").WebReadString('AddNewString');                                          //读取注册表
   document.getElementById("WebOffice").WebCloseKey();                                                                        //关闭注册表
    alert(Content);
  }
  catch(e){
    alert(e.description);
   document.getElementById("WebOffice").WebCloseKey();
  } 
} 

//写入注册表(十进制)
function WebWriteRegString(){
  try{
   document.getElementById("WebOffice").WebOpenKey('HKEY_CURRENT_USER', 'Software\\Microsoft\\Office\\12.0\\Common\\Toolbars');    //打开注册表
    var result =document.getElementById("WebOffice").WebWriteString('AddNewString','1234');                                   //写入注册表
   document.getElementById("WebOffice").WebCloseKey();                                                                        //关闭注册表
    if (result) {
      alert("写入注册表成功!");
    }else{
      alert("写入注册表失败!");
    }
  }
  catch(e){
    alert("写入注册表失败!原因:"+e.description);
   document.getElementById("WebOffice").WebCloseKey();
  } 
} 

//接受文档中全部痕迹
function WebAcceptAllRevisions(){
 document.getElementById("WebOffice").WebObject.Application.ActiveDocument.AcceptAllRevisions();
  var mCount =document.getElementById("WebOffice").WebObject.Application.ActiveDocument.Revisions.Count;
  if(mCount>0){
    return false;
  }else{
    return true;
  }
}

//打开的服务器上的文档并修复
function WebOpenAndRepair(){
 document.getElementById("WebOffice").WebRepairMode = true;   //打开修复模式
 document.getElementById("WebOffice").WebOpen();              //重调刚才打开的服务器上的文档
  StatusMsg(WebOffice.Status);
 document.getElementById("WebOffice").WebRepairMode = false;  //关闭修复模式
}

//打开本机上的文档并修复
function WebOpenLocalAndRepair(){
 document.getElementById("WebOffice").WebRepairMode = true;   //打开修复模式
 document.getElementById("WebOffice").WebOpenLocal();         //打开本机上的文档
  StatusMsg(WebOffice.Status);
 document.getElementById("WebOffice").WebRepairMode = false;  //关闭修复模式
}


if(document.getElementById("WebOffice")){
	document.getElementById("WebOffice").__WebOpen = document.getElementById("WebOffice").WebOpen;
	document.getElementById("WebOffice").WebOpen = function(){
	    document.getElementById("WebOffice").WebRepairMode = true;   //打开修复模式
	    document.getElementById("WebOffice").__WebOpen();
	    document.getElementById("WebOffice").WebRepairMode = false;  //关闭修复模式
	
	}
}