javascript OFFICE 컨트롤 테스트 코드


// JS
var TANGER_OCX_bDocOpen = false;
var TANGER_OCX_filename;//
var filetype="";//
var savetype;//
var TANGER_OCX_OBJ; //
var TANGER_OCX_Username=" ";//User Name
var TANGER_OCX_key="";// key
var IsFileOpened; //
var svisble=true;//
var TANGER_OCX_strOp; // 。1: ;2: ;3:
var TANGER_OCX_attachName; //
var TANGER_OCX_attachURL; // URL
var TANGER_OCX_actionURL; // URL


// ,
function FormDisabled(bool)
{
var formid=document.forms.item(0)
var elelength=formid.length;
for (var i=0; i<elelength; i++)
{formid.elements[i].disabled = bool;}
// , , ,
TANGER_OCX_OBJ.TitleBar=!bool;
TANGER_OCX_OBJ.Statusbar=!bool;
TANGER_OCX_OBJ.ToolBars=!bool;
TANGER_OCX_OBJ.Menubar=!bool;
}
//
function NtkoHelp()
{
window.open("help.htm","help");
}
//
function popupDocWin(turl){
var aw = window.screen.availWidth;
var ah = window.screen.availHeight;
window.open(turl,"office");
}
//
function CreatNew(DocType)
{
TANGER_OCX_OBJ = document.all.item("TANGER_OCX");
TANGER_OCX_OBJ.CreateNew(DocType);
var useUTF8 = (document.charset == "utf-8");
TANGER_OCX_OBJ.IsUseUTF8Data = useUTF8;
try
{
// url, SaveToURL
TANGER_OCX_actionURL = document.forms[0].action;
//
TANGER_OCX_strOp = document.all.item("TANGER_OCX_op").innerHTML;
//
TANGER_OCX_attachName = document.all.item("TANGER_OCX_attachName").innerHTML;
// URL
TANGER_OCX_attachURL = document.all.item("TANGER_OCX_attachURL").innerHTML;
TANGER_OCX_key = document.all.item("TANGER_OCX_key").innerHTML;
}catch(err){}finally{};
}
// 。 TANGER_OCX_OBJ
// , , 。
function TANGER_OCX_Init(initdocurl)
{
TANGER_OCX_OBJ = document.all.item("TANGER_OCX");
var useUTF8 = (document.charset == "utf-8");
TANGER_OCX_OBJ.IsUseUTF8Data = useUTF8;
try
{
// url, SaveToURL
TANGER_OCX_actionURL = document.forms[0].action;
//
TANGER_OCX_strOp = document.all.item("TANGER_OCX_op").innerHTML;
//
TANGER_OCX_attachName = document.all.item("TANGER_OCX_attachName").innerHTML;
// URL
TANGER_OCX_attachURL = document.all.item("TANGER_OCX_attachURL").innerHTML;
try{
TANGER_OCX_key = document.all.item("TANGER_OCX_key").innerHTML;
}catch(err){}finally{};
TANGER_OCX_OBJ.SetAutoCheckSignKey(TANGER_OCX_key);
switch(TANGER_OCX_strOp)
{
case "1":
if(initdocurl!="")
{
TANGER_OCX_OBJ.BeginOpenFromURL(initdocurl,true,false);// :URL, ,
}
break;
case "2":
if(TANGER_OCX_attachURL)
{
TANGER_OCX_OBJ.BeginOpenFromURL(TANGER_OCX_attachURL,true,false);
}
else
{
if(initdocurl!="")
TANGER_OCX_OBJ.BeginOpenFromURL(initdocurl,true,false);
}
break;
case "3":
if(TANGER_OCX_attachURL)
{
TANGER_OCX_OBJ.BeginOpenFromURL(TANGER_OCX_attachURL,true,true);
}
break;
default: // , ,TANGER_OCX_strOp url
// URL URL, ?openform
var keystr = "?openform&".toUpperCase();
var parastring = window.location.search;
//alert(parastring);
var urlbegin = parastring.toUpperCase().indexOf(keystr);
if(-1 != urlbegin)
{
TANGER_OCX_strOp = parastring.substr(urlbegin+keystr.length);
//alert(TANGER_OCX_strOp);
// WPS
var wpsKey = "vwWpsTurl".toUpperCase();
var isWpsTemplateURL = (-1 != parastring.toUpperCase().indexOf(wpsKey));
if(!isWpsTemplateURL)
{
TANGER_OCX_OBJ.BeginOpenFromURL(TANGER_OCX_strOp,true,false);
}
else
{
TANGER_OCX_OBJ.BeginOpenFromURL(TANGER_OCX_strOp,true,false,"WPS.Document");
}
}
break;
}
}
catch(err){
alert(" :" + err.number + ":" + err.description);
}
finally{
}
}
// OnSubmit , 。
function TANGER_OCX_doFormOnSubmit()
{
var form = document.forms[0];
if (form.onsubmit)
{
var retVal = form.onsubmit();
if (typeof retVal == "boolean" && retVal == false)
return false;
}
return true;
}
//
function addMyMenuItems()
{
try{
TANGER_OCX_OBJ = document.all.item("TANGER_OCX");
//
TANGER_OCX_OBJ.AddFileMenuItem(' - ',false,true,1);
TANGER_OCX_OBJ.AddFileMenuItem('');
//
TANGER_OCX_OBJ.AddCustomMenuItem(' 1: ',false,false,1);
TANGER_OCX_OBJ.AddCustomMenuItem('');
TANGER_OCX_OBJ.AddCustomMenuItem(' 2',false,false,2);
TANGER_OCX_OBJ.AddCustomMenuItem('');
TANGER_OCX_OBJ.AddCustomMenuItem(' 3',false,false,3);
TANGER_OCX_OBJ.AddCustomMenuItem('');
TANGER_OCX_OBJ.AddCustomMenuItem(' ',false,true,4);
}
catch(err)
{
}
}
// 。 SaveToURL 。
// , 。
function TANGER_OCX_SaveDoc(fileName)
{
var retStr=new String;
var newwin,newdoc;
if(fileName=="")
{
alert(" !");
return;
}
try
{
if(!TANGER_OCX_doFormOnSubmit())return;
if(!TANGER_OCX_bDocOpen)
{
alert(" 。");
return;
}
//
var deleteFile = "";
//
document.all.item("TANGER_OCX_filename").value = fileName;
switch(TANGER_OCX_strOp)
{
case "3":
alert(" , 。");
break;
case "2": //
deleteFile = (TANGER_OCX_attachName=="")?"":"%%Detach="+escape(TANGER_OCX_attachName);
case "1":
//
default:
retStr = TANGER_OCX_OBJ.SaveToURL(TANGER_OCX_actionURL,
document.all.item("NTKO_UPLOADFIELD").name, //
deleteFile,
fileName,
0 // forms[0]
);
retMhtStr = TANGER_OCX_OBJ.SaveAsOtherFormatToURL(
1,
TANGER_OCX_actionURL,
document.all.item("NTKO_UPLOADFIELD").name, //
"%%Detach=newdoc.mht",
"newdoc.mht",
0 // forms[0]
);
newwin = window.open("","_blank","left=200,top=200,width=400,height=200,status=0,toolbar=0,menubar=0,location=0,scrollbars=0,resizable=0",false);
newdoc = newwin.document;
newdoc.open();
newdoc.write("<center><hr>"+retStr+"<hr><input type=button VALUE=' ' onclick='window.close()'></center>");
newdoc.close();
//window.alert(retStr);
window.opener.location.reload();
window.close();
break;
}
}
catch(err){
alert(" URL:" + err.number + ":" + err.description);
}
finally{
}
}

// 。
function TANGER_OCX_OnDocumentOpened(str, obj)
{
try
{
TANGER_OCX_bDocOpen = true;
//
TANGER_OCX_SetDocUser(TANGER_OCX_Username);
if(obj)
{
switch(TANGER_OCX_strOp)
{
case "1":
case "2":
TANGER_OCX_OBJ.SetReadOnly(false);
break;
case "3":
TANGER_OCX_OBJ.SetReadOnly(true);
FormDisabled(true);// input
break;
default:
break;
}
}
}
catch(err){

}
finally{
}
}
function SaveAsHTML(URL,uploadfield,fileName)
{
try
{
var retStr = TANGER_OCX_OBJ.PublishAsHTMLToURL(
URL,uploadfield, "__Click=0&filetitle="+escape(document.forms(0).filetitle.value)+
"&fileother="+escape(document.forms(0).fileother.value)+
"&fileid="+escape(document.forms(0).fileid.value)+
"&filename="+fileName,
fileName//
);
var newwin = window.open("","_blank","left=200,top=200,width=400,height=200,status=0,toolbar=0,menubar=0,location=0,scrollbars=0,resizable=0",false);
var newdoc = newwin.document;
newdoc.open();
newdoc.write("<center><hr>"+retStr+"<hr><input type=button VALUE=' ' onclick='window.close()'></center>");
newdoc.close();
}
catch(err){
alert(" URL:" + err.number + ":" + err.description);
}
finally{
}
}
// pdf
function saveFileAsPdfToUrl(URL,uploadfield,fileName)
{
try
{
var retStr = TANGER_OCX_OBJ.PublishAsPDFToURL(
URL,uploadfield,"__Click=0&filename="+fileName+
"&filetitle="+document.all("filetitle").value+
"&fileother="+document.all("fileother").value+
"&fileid="+document.all("fileid").value,
fileName,
"",
null,
true,
false,
false,
null,
false,
true
);
}
catch(err){
alert(" URL:" + err.number + ":" + err.description);
}
finally{
}
}
//
function onPageClose()
{
if(IsFileOpened)
{
if(!TANGER_OCX_OBJ.ActiveDocument.Saved)
{
if(confirm( " , , ?"))
{
TANGER_OCX_SaveDoc("newdoc.doc");
}
}
window.opener.location.reload();
}
}

//
function setFileOpenedOrClosed(bool)
{
IsFileOpened = bool;
fileType = TANGER_OCX_OBJ.DocType ;
}
function trim(str)
{ //
return str.replace(/(^\s*)|(\s*$)/g, "");
}

//
function TANGER_OCX_SetDocUser(cuser)
{
with(TANGER_OCX_OBJ.ActiveDocument.Application)
{
UserName = cuser;
UserInitials=cuser;
}
}
function addServerSecSign()
{
var signUrl=document.all("secSignFileUrl").options[document.all("secSignFileUrl").selectedIndex].value;
if(IsFileOpened)
{
if(TANGER_OCX_OBJ.doctype==1||TANGER_OCX_OBJ.doctype==2)
{
try
{TANGER_OCX_OBJ.AddSecSignFromURL("ntko",signUrl);}
catch(error){}
}
else
{alert(" .");}
}
}
function addLocalSecSign()
{
if(IsFileOpened)
{
if(TANGER_OCX_OBJ.doctype==1||TANGER_OCX_OBJ.doctype==2)
{
try
{TANGER_OCX_OBJ.AddSecSignFromLocal("ntko","");}
catch(error){}
}
else
{alert(" .");}
}
}
function addEkeySecSign()
{
if(IsFileOpened)
{
if(TANGER_OCX_OBJ.doctype==1||TANGER_OCX_OBJ.doctype==2)
{
try
{TANGER_OCX_OBJ.AddSecSignFromEkey("ntko");}
catch(error){}
}
else
{alert(" .");}
}
}
function addHandSecSign()
{
if(IsFileOpened)
{
if(TANGER_OCX_OBJ.doctype==1||TANGER_OCX_OBJ.doctype==2)
{
try
{TANGER_OCX_OBJ.AddSecHandSign("ntko");}
catch(error){}
}
else
{alert(" .");}
}
}

function addServerSign(signUrl)
{
if(IsFileOpened)
{
try
{
TANGER_OCX_OBJ.AddSignFromURL("ntko",//
signUrl,// url
100,//
100,// Relative
"ntko",// DoCheckSign ,
3, //Relative, 1-4。 1: ;2: ;3: 4: ,
100,// , 100%
1); //0 ,1

}
catch(error){}
}
}

function addLocalSign()
{
if(IsFileOpened)
{
try
{
TANGER_OCX_OBJ.AddSignFromLocal("ntko",//
"",//
true,//
100,//
100,// Relative
"ntko",// DoCheckSign ,
3, //Relative, 1-4。 1: ;2: ;3: 4: ,
100,// , 100%
1); //0 ,1
}
catch(error){}
}
}
function addPicFromUrl(picURL)
{
if(IsFileOpened)
{
if(TANGER_OCX_OBJ.doctype==1||TANGER_OCX_OBJ.doctype==2)
{
try
{
TANGER_OCX_OBJ.AddPicFromURL(picURL,// url
false,// , false ,top left
100,//left
100,//top Relative
1, //Relative, 1-4。 1: ;2: ;3: 4: ,
100,// , 100%
1); //0 ,1

}
catch(error){}
}
else
{alert(" .");}
}
}
function addPicFromLocal()
{
if(IsFileOpened)
{
try
{
TANGER_OCX_OBJ.AddPicFromLocal("",//
true,//
false,//
100,//
100,// Relative
1, //Relative, 1-4。 1: ;2: ;3: 4: ,
100,// , 100%
1); //0 ,1
}
catch(error){}
}
}

function TANGER_OCX_AddDocHeader(strHeader)
{
if(!IsFileOpened)
{return;}
var i,cNum = 30;
var lineStr = "";
try
{
for(i=0;i<cNum;i++) lineStr += "_"; //
with(TANGER_OCX_OBJ.ActiveDocument.Application)
{
Selection.HomeKey(6,0); // go home
Selection.TypeText(strHeader);
Selection.TypeParagraph(); //
Selection.TypeText(lineStr); //
// Selection.InsertSymbol(95,"",true); //
Selection.TypeText("★");
Selection.TypeText(lineStr); //
Selection.TypeParagraph();
//Selection.MoveUp(5, 2, 1); // , Shift ,
Selection.HomeKey(6,1); //
Selection.ParagraphFormat.Alignment = 1; //
with(Selection.Font)
{
NameFarEast = " ";
Name = " ";
Size = 12;
Bold = false;
Italic = false;
Underline = 0;
UnderlineColor = 0;
StrikeThrough = false;
DoubleStrikeThrough = false;
Outline = false;
Emboss = false;
Shadow = false;
Hidden = false;
SmallCaps = false;
AllCaps = false;
Color = 255;
Engrave = false;
Superscript = false;
Subscript = false;
Spacing = 0;
Scaling = 100;
Position = 0;
Kerning = 0;
Animation = 0;
DisableCharacterSpaceGrid = false;
EmphasisMark = 0;
}
Selection.MoveDown(5, 3, 0); // 3
}
}
catch(err){
alert(" :" + err.number + ":" + err.description);
}
finally{
}
}

function insertRedHeadFromUrl(headFileURL)
{
if(TANGER_OCX_OBJ.doctype!=1)//TANGER_OCX_OBJ.doctype=1 word
{return;}
TANGER_OCX_OBJ.ActiveDocument.Application.Selection.HomeKey(6,0);//
TANGER_OCX_OBJ.addtemplatefromurl(headFileURL);//
}
function openTemplateFileFromUrl(templateUrl)
{
TANGER_OCX_OBJ.openFromUrl(templateUrl);
}
function doHandSign()
{
/*if(TANGER_OCX_OBJ.doctype==1||TANGER_OCX_OBJ.doctype==2)// word excel .doctype=1 "word" ,doctype=2 "excel"
{*/
TANGER_OCX_OBJ.DoHandSign2(
"ntko",//
"ntko",//signkey,DoCheckSign( ) 。
0,//left
0,//top
1,//relative, .0: , ,Left,Top 。1: ;2: ;3: 4: , ( )
100);
//}
}
function SetReviewMode(boolvalue)
{
if(TANGER_OCX_OBJ.doctype==1)
{
TANGER_OCX_OBJ.ActiveDocument.TrackRevisions = boolvalue;//
}
}

function setShowRevisions(boolevalue)
{
if(TANGER_OCX_OBJ.doctype==1)
{
TANGER_OCX_OBJ.ActiveDocument.ShowRevisions =boolevalue;//
}
}
//
function TANGER_OCX_AllRevisions(bool)
{
if(bool)
{
TANGER_OCX_OBJ.ActiveDocument.AcceptAllRevisions();//
}
else
{
TANGER_OCX_OBJ.ActiveDocument.Application.WordBasic.RejectAllChangesInDoc();//
}
}
function setFilePrint(boolvalue)
{
TANGER_OCX_OBJ.fileprint=boolvalue;//
}
function setFileNew(boolvalue)
{
TANGER_OCX_OBJ.FileNew=boolvalue;//
}
function setFileSaveAs(boolvalue)
{
TANGER_OCX_OBJ.FileSaveAs=boolvalue;//
}

function setIsNoCopy(boolvalue)
{
TANGER_OCX_OBJ.IsNoCopy=boolvalue;//
}
function DoCheckSign()
{
if(IsFileOpened)
{
var ret = TANGER_OCX_OBJ.DoCheckSign
(
false,/* IsSilent FAlSE, , , */
"ntko"// signkey, "ntko"
);// ,
//alert(ret);
}
}
function setToolBar()
{
TANGER_OCX_OBJ.ToolBars=!TANGER_OCX_OBJ.ToolBars;
}
function setMenubar()
{
TANGER_OCX_OBJ.Menubar=!TANGER_OCX_OBJ.Menubar;
}
function setInsertMemu()
{
TANGER_OCX_OBJ.IsShowInsertMenu=!TANGER_OCX_OBJ.IsShowInsertMenu;
}
function setEditMenu()
{
TANGER_OCX_OBJ.IsShowEditMenu=!TANGER_OCX_OBJ.IsShowEditMenu;
}
function setToolMenu()
{
TANGER_OCX_OBJ.IsShowToolMenu=!TANGER_OCX_OBJ.IsShowToolMenu;
}

//
function initCustomMenus1()
{
var myobj = TANGER_OCX_OBJ;
for(var menuPos=0;menuPos<1;menuPos++)
{
myobj.AddCustomMenu2(menuPos," "+"(&"+menuPos+")");
for(var submenuPos=0;submenuPos<1;submenuPos++)
{
myobj.AddCustomMenuItem2(menuPos,submenuPos,-1,true," ",false);
//
for(var subsubmenuPos=0;subsubmenuPos<3;subsubmenuPos++)
{
if(0 ==subsubmenuPos)//
{
myobj.AddCustomMenuItem2(menuPos,submenuPos,subsubmenuPos,false,
" ",false,menuPos*100+submenuPos*20+subsubmenuPos);
}
if(1 ==subsubmenuPos)//
{
myobj.AddCustomMenuItem2(menuPos,submenuPos,subsubmenuPos,false,
" ",false,menuPos*100+submenuPos*20+subsubmenuPos);
}
if(2==subsubmenuPos)
{
myobj.AddCustomMenuItem2(menuPos,submenuPos,subsubmenuPos,false,
" ",false,menuPos*100+submenuPos*20+subsubmenuPos);
}
}
}
}
}
//
function controlStyle()
{
var myobj = TANGER_OCX_OBJ;
for(var menuPos=0;menuPos<1;menuPos++)
{
myobj.AddCustomMenu2(menuPos," "+"(&"+menuPos+")");
for(var submenuPos=0;submenuPos<1;submenuPos++)
{
myobj.AddCustomMenuItem2(menuPos,submenuPos,-1,true," ",false);
//
for(var subsubmenuPos=0;subsubmenuPos<2;subsubmenuPos++)
{
if(0 ==subsubmenuPos)//
{
myobj.AddCustomMenuItem2(menuPos,submenuPos,subsubmenuPos,false,
" ",false,menuPos*100+submenuPos*20+subsubmenuPos);
}
if(1 ==subsubmenuPos)//
{
myobj.AddCustomMenuItem2(menuPos,submenuPos,subsubmenuPos,false,
" ",false,menuPos*100+submenuPos*20+subsubmenuPos);
}
}
}
}
}
//
function objside()
{
document.all.officecontrol.style.position="absolute";
document.all.officecontrol.style.left="0px";
document.all.officecontrol.style.top="0px";
document.all.officecontrol.style.width=document.body.clientWidth;//
document.all.officecontrol.style.height=document.body.clientHeight;//
}
//
function objside2()
{
document.all.officecontrol.style.position="relative";
document.all.officecontrol.style.left="0px";
document.all.officecontrol.style.top="0px";
document.all.officecontrol.style.width="100%";
document.all.officecontrol.style.height="980px";
}
//
function ObjectDisplay(boolvalue)
{
var obj=document.getElementById("objside");
if(!boolvalue)
{
obj.style.display="none";
}
else
{
obj.style.display="block";
}
}

/**
* ;
*/
Date.prototype.format = function(format){
/*
* eg:format="YYYY-MM-dd hh:mm:ss";
*/
var o = {
"Y+":this.getYear(),//
"M+" : this.getMonth()+1, //month
"d+" : this.getDate(), //day
"h+" : this.getHours(), //hour
"m+" : this.getMinutes(), //minute
"s+" : this.getSeconds(), //second
"q+" : Math.floor((this.getMonth()+3)/3), //quarter
"S" : this.getMilliseconds() //millisecond
}

if(/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
}

for(var k in o) {
if(new RegExp("("+ k +")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
}
}
return format;
}

좋은 웹페이지 즐겨찾기