본문 바로가기
WEB/넥사크로

(넥사크로 14) 엑셀 복사하여 그리드에 붙여 넣기

by iiaii 2018. 12. 13.
반응형

 /*****************************************************************************************

 * 함  수  명 : grd_Detail_onkeydown

 * 입      력 : 1.obj      : Form

  2.authSet  : 버튼 권한

 * 반      환 :   

 * 기      능 :  붙여넣기 - 그리드 onkeydown 이벤트 

 *****************************************************************************************/ 

this.grd_Detail_onkeydown = function(obj:Grid, e:nexacro.KeyEventInfo)

{

this.gfn_grdCopy_Paste(obj, e, user_id);

}


 /*****************************************************************************************

 * 함  수  명 : gfn_grdCopy_Paste

 * 입      력 : 1.obj      : Form

  2.authSet  : 버튼 권한

 * 반      환 :   

 * 기      능 :  엑셀 내역 그리드로 복사

 *****************************************************************************************/ 

this.gfn_grdCopy_Paste = function (obj, e,user_id)

{


if(e.ctrlKey){

if(e.keycode == 67){

var strGrdDsNm = obj.binddataset;

var v_clip = "";

var strSeperate = " ";

for (var i= nexacro.toNumber(obj.selectstartrow);i<= nexacro.toNumber(obj.selectendrow);i++) {

for (var j=nexacro.toNumber(obj.selectstartcol);j<=nexacro.toNumber(obj.selectendcol);j++) {


if (j < obj.selectendcol) {

v_clip += obj.getCellValue(i,j) + strSeperate;

} else {

v_clip += obj.getCellValue(i,j);

}

}

if (i < obj.selectendrow) {

v_clip += "\r\n";

}

}

v_clip += "\r\n";

system.clearClipboard();

system.setClipboard("CF_TEXT",v_clip);

trace("strGrdDsNm " + strGrdDsNm);

trace("v_clip " + v_clip);

} else if(e.keycode == 86) {


var bAddrow = true;

if (!this.utlf_IsNull(this.gfn_grdCopy_Paste.arguments[2])) {

bAddrow = this.gfn_grdCopy_Paste.arguments[2];

}

//Grid Binddataset

var strGrdDsNm = obj.binddataset;

//cell count

var nGrdCellCnt = obj.getCellCount("body");

//cell position

var nGrdCellPos = obj.getCellPos();

//trace("nGrdCellPos  " + nGrdCellPos);

//row position

var nRowPos = eval("this." + strGrdDsNm).rowposition;

trace("nRowPos  " + nRowPos);

//arrText2 index

var k = 0;

//Dataset rowcount

var nDsRowCnt = eval("this." + strGrdDsNm).getRowCount();


trace("nDsRowCnt  " + nDsRowCnt);

//var t_clip = system.getClipboard("CF_UNICODETEXT");

var t_clip = system.getClipboard("CF_TEXT");

var strText = new String(t_clip);

var arrText = new Array();

var arrText2 = new Array();

arrText = strText.split("\r\n");

trace("t_clip " + t_clip);

trace("strText " + strText);

trace("arrText " + arrText);

trace("arrText2 " + arrText2);

if (nDsRowCnt < (arrText.length + nRowPos -1)) {

if (bAddrow) {

} else {

return false;

}

}

//복사한 Row만큼

var oDs =  eval("this." + strGrdDsNm);

for (var i=0;i<arrText.length;i++) {

if (this.utlf_IsNull(arrText[i])) {

return;

}

arrText2 = arrText[i].split(" ");


trace("arrText2:" + arrText2);

//기존 dataset갯수보다 많은 경우

/*if ( nDsRowCnt <= nRowPos) {

var nAddrow = oDs.addRow();

}

*/

var nLoopCnt = (nGrdCellPos + arrText2.length);

if (nLoopCnt > nGrdCellCnt) {

nLoopCnt = nGrdCellCnt;

}

//Dataset setcolumn

trace("nGrdCellPos  " + nGrdCellPos);

trace("nLoopCnt  " + nLoopCnt);

k = 0;

for (var j=nGrdCellPos;j<nLoopCnt;j++) {

var colid = obj.getCellProperty("body", j, "text").substr(5);

oDs.setColumn(nRowPos, colid, arrText2[k]);

k++;

}

nRowPos++;

eval("this." + strGrdDsNm).rowposition = nRowPos;

}

return true;

}

}

}


/**


* Null에 해당하는 값 체크.

* @param : sValue - Null 확인 밗

* @return : true/false

* @example : utlf_IsNull(sValue);

*/

this.utlf_IsNull = function (sValue)

{

if( new String(sValue).valueOf() == "undefined") 

return true;

if( sValue == null )

return true;

if( ("x"+sValue == "xNaN") && ( new String(sValue.length).valueOf() == "undefined" ) )

return true;

if( sValue.length == 0 )

return true;

return false;

}

반응형