반응형
How copy and paste excel columns to HTML table with inputs?
엑셀의 내용 카피해서 웹화면 input에 순서대로 붙여넣기.
https://www.codeproject.com/Questions/1212303/How-copy-and-paste-excel-columns-to-HTML-table-wit
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
</head>
<body>
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
</thead>
<tbody>
<tr>
<td><input type="text"></td>
<td><input type="text"></td>
<td><input type="text"></td>
</tr>
<tr>
<td><input type="text"></td>
<td><input type="text"></td>
<td><input type="text"></td>
</tr>
<tr>
<td><input type="text"></td>
<td><input type="text"></td>
<td><input type="text"></td>
</tr>
</tbody>
</table>
<script>
$(document).ready(function () {
$('td input').bind('paste', null, function (e) {
$txt = $(this);
setTimeout(function () {
var values = $txt.val().split(/\s+/);
var currentRowIndex = $txt.parent().parent().index();
var currentColIndex = $txt.parent().index();
var totalRows = $('#example tbody tr').length;
var totalCols = $('#example thead th').length;
var count =0;
for (var i = currentColIndex; i < totalCols; i++) {
if (i != currentColIndex)
if (i != currentColIndex)
currentRowIndex = 0;
for (var j = currentRowIndex; j < totalRows; j++) {
var value = values[count];
var inp = $('#example tbody tr').eq(j).find('td').eq(i).find('input');
inp.val(value);
count++;
}
}
}, 0);
});
});
</script>
</body>
</html>
반응형
'프로그래밍 > Script' 카테고리의 다른 글
[javascript] IIFE - 즉시 실행 함수 표현(IIFE, Immediately Invoked Function Expression) (0) | 2022.03.23 |
---|---|
[javascript] 전체 화면 Full screen (0) | 2022.03.15 |
[javascript] 숫자 세자리 콤마 제거하기, ASP 숫자형 리턴 (0) | 2022.02.04 |
[javascript] ES6 for beginners, ES6 문법 + 활용 패턴 살펴보기 (0) | 2022.01.24 |
[script] 생활코딩 마인드맵 라이브러리 cytoscape 사용법 (0) | 2022.01.19 |