반응형

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

 

[Solved] How copy and paste excel columns to HTML table with inputs? - CodeProject

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900

www.codeproject.com

<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>

 

반응형
반응형

웹에서 요소 복사. HTML DOM execCommand() Method

현재 선택영역의 텍스트를 인자로 받은 값을 통해 변환시킵니다. 

execCommand 에서 "copy" 명령 사용

document.execCommand('Italic')           // 기울이기
document.execCommand('Underline')        // 밑줄
document.execCommand('StrikeThrough')    // 중간줄
document.execCommand('Cut')              // 자르기
document.execCommand('Copy')             // 복사하기
document.execCommand('Paste')            // 붙혀넣기
document.execCommand('Undo')             // 실행취소
document.execCommand('Redo')             // 다시실행
document.execCommand('insertorderedList')    // 글번호 매기기
document.execCommand('insertunorderdList')   // 글머리 매기기
document.execCommand('outdent')          // 내어쓰기
document.execCommand('indent')           // 들여쓰기
document.execCommand('justifyleft')      // 왼쪽정렬
document.execCommand('justifycenter')    // 가운데정렬
document.execCommand('justifyright')     // 오른쪽정렬

Syntax

document.execCommand(command, showUI, value)

Parameter Values

ValueDescription

command Specifies the name of the command to execute on the selected section. 

Legal values: 
"backColor"
"bold"
"createLink"
"copy"
"cut"
"defaultParagraphSeparator"
"delete"
"fontName"
"fontSize"
"foreColor"
"formatBlock"
"forwardDelete"
"insertHorizontalRule"
"insertHTML"
"insertImage"
"insertLineBreak"
"insertOrderedList"
"insertParagraph"
"insertText"
"insertUnorderedList"
"justifyCenter"
"justifyFull"
"justifyLeft"
"justifyRight"
"outdent"
"paste"
"redo"
"selectAll"
"strikethrough"
"styleWithCss"
"superscript"
"undo"
"unlink"
"useCSS"
showUI A Boolean, specifies if the UI should be shown or not
value Some commands need a value to be completed

 

반응형

+ Recent posts