Skip to content

Instantly share code, notes, and snippets.

@binjoo
Created November 5, 2012 09:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save binjoo/4016127 to your computer and use it in GitHub Desktop.
Save binjoo/4016127 to your computer and use it in GitHub Desktop.
JAVASCRIPT:从EXECL中拷贝多行数据,粘贴至HTML INPUT控件中。
/**
* 从EXECL中拷贝多行数据,粘贴至HTML INPUT控件中。
* event 用户键盘操作对象
* obj 被粘贴的控件对象
* num 第几行
**/
function copyValue(event, obj ,num){
if (event != null && event.ctrlKey && event.keyCode == 86) {
var text = window.clipboardData.getData("Text");
var input = document.getElementsByName(obj.name);
if(text.indexOf("\r\n") != -1){
event.keyCode = 0;
var sheetrows = text.split("\r\n");
for(var i=num-1,j=0; i<input.length; i++,j++){
if(typeof(sheetrows[j]) != 'undefined' && typeof(input[i]) != 'undefined'){
input[i].value = sheetrows[j];
}else{
return false;
}
}
}else{
obj.value = text;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment