Paste from Excel stopped working

7 posts, 0 answers
  1. David
    David avatar
    159 posts
    Member since:
    Mar 2014

    Posted 07 Jul Link to this post

    I implemented paste from Excel based on info from this forum. With latest version of RadGrid it does not work any longer. I am having trouble to fix it. Can you help, please?

    function pasteFromExcel() {

                var ua = window.navigator.userAgent;
                var msie = ua.indexOf("MSIE ");

                if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) {
                    //continue for IE
                }
                else {
                    jInfo("Paste from Excel works only in IE (due security policies of other browsers)","INFO")
                }

                if (!lastFocused) return;
                var clipData = window.clipboardData.getData('Text');
                var crlf = String.fromCharCode(13) + String.fromCharCode(10);
                var table = clipData.split(crlf);
                for (var tRow = 0; tRow < table.length - 1; tRow++)
                    table[tRow] = table[tRow].split(String.fromCharCode(9));
                Array.remove(table, table[table.length - 1]);
                fillTable(table);

                $('#<%= lbtnSaveMarketAccessArea.ClientID %>').attr("class", "button3D_Yellow");
            }

            function fillTable(table) {
                var pCell = lastFocused.parentNode;
                var pRow = pCell.parentNode;
                var pBody = pRow.parentNode;
                var maxRows = pBody.rows.length;
                var maxCols = pRow.cells.length;

                for (var row = 0; row < table.length; row++) {
                    for (var col = 0; col < table[row].length; col++) {
                        var cCellIndex = pCell.cellIndex + col;
                        var cRowIndex = pRow.sectionRowIndex + row;

                        if (cRowIndex < maxRows && cCellIndex < maxCols) {
                            var cCell = pBody.rows[cRowIndex].cells[cCellIndex];
                            var pInput = cCell.getElementsByTagName("input")[0];

                            pInput.style.backgroundColor = "#F7FAFF";
                            pInput.value = table[row][col];
                        }
                    }
                }
            }

  2. David
    David avatar
    159 posts
    Member since:
    Mar 2014

    Posted 18 Jul Link to this post

    Any help?
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1800 posts

    Posted 21 Jul Link to this post

    Hi David,

    I am not sure how this is related to the built-in functionality of RadGrid, but I could suggest that you inspect your browser's console and see if there are JavaScript errors thrown from your custom code. This could help you identify the cause of the problem. You could also debug your custom code and see which part of the code fails.


    Regards,
    Konstantin Dikov
    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  5. David
    David avatar
    159 posts
    Member since:
    Mar 2014

    Posted 21 Jul in reply to Konstantin Dikov Link to this post

    Hi Konstantin,

       Some of client side functions changed with a last version of RadGrid.

       Picture attached

  6. David
    David avatar
    159 posts
    Member since:
    Mar 2014

    Posted 29 Jul in reply to David Link to this post

    Konstantin,

       Any recommendations?

  7. David
    David avatar
    159 posts
    Member since:
    Mar 2014

    Posted 22 Aug Link to this post

    To anybody who struggles with the same issue i was able to solve it myself (no thanks to Telerik)

      var lastFocused;

            function pasteFromExcel() {

                var ua = window.navigator.userAgent;
                var msie = ua.indexOf("MSIE ");

                if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) {
                    //continue for IE
                }
                else {
                    jInfo("Paste from Excel works only in IE (due security policies of other browsers)", "INFO")
                }

                if (!lastFocused) return;
                var clipData = window.clipboardData.getData('Text');
                var crlf = String.fromCharCode(13) + String.fromCharCode(10);
                var table = clipData.split(crlf);
                for (var tRow = 0; tRow < table.length - 1; tRow++)
                    table[tRow] = table[tRow].split(String.fromCharCode(9));
                Array.remove(table, table[table.length - 1]);
                fillTable(table);
            }

            function fillTable(clipboard_table) {

                var pCell = lastFocused.parentNode;
                var pRow = pCell.parentNode;
                var pBody = pRow.parentNode;
                var topLevel = pBody.parentNode;
                var maxRows = topLevel.childElementCount;
                var maxCols = pBody.cells.length;

                for (var row = 0; row < clipboard_table.length; row++) {
                    for (var col = 0; col < clipboard_table[row].length; col++) {

                        var cCellIndex = pRow.cellIndex + col;
                        var cRowIndex = pBody.sectionRowIndex + row;

                        if (cRowIndex < maxRows && cCellIndex < maxCols) {
                            var cCell = topLevel.rows[cRowIndex].cells[cCellIndex];
                            var pInput = cCell.getElementsByTagName("input")[0];

                            pInput.style.backgroundColor = "#F7FAFF";
                            pInput.value = clipboard_table[row][col];
                        }
                    }
                }
            }

  8. David
    David avatar
    159 posts
    Member since:
    Mar 2014

    Posted 22 Aug Link to this post

    To anybody who struggles with the same issue i was able to solve it myself (no thanks to Telerik)

      var lastFocused;

            function pasteFromExcel() {

                var ua = window.navigator.userAgent;
                var msie = ua.indexOf("MSIE ");

                if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) {
                    //continue for IE
                }
                else {
                    jInfo("Paste from Excel works only in IE (due security policies of other browsers)", "INFO")
                }

                if (!lastFocused) return;
                var clipData = window.clipboardData.getData('Text');
                var crlf = String.fromCharCode(13) + String.fromCharCode(10);
                var table = clipData.split(crlf);
                for (var tRow = 0; tRow < table.length - 1; tRow++)
                    table[tRow] = table[tRow].split(String.fromCharCode(9));
                Array.remove(table, table[table.length - 1]);
                fillTable(table);
            }

            function fillTable(clipboard_table) {

                var pCell = lastFocused.parentNode;
                var pRow = pCell.parentNode;
                var pBody = pRow.parentNode;
                var topLevel = pBody.parentNode;
                var maxRows = topLevel.childElementCount;
                var maxCols = pBody.cells.length;

                for (var row = 0; row < clipboard_table.length; row++) {
                    for (var col = 0; col < clipboard_table[row].length; col++) {

                        var cCellIndex = pRow.cellIndex + col;
                        var cRowIndex = pBody.sectionRowIndex + row;

                        if (cRowIndex < maxRows && cCellIndex < maxCols) {
                            var cCell = topLevel.rows[cRowIndex].cells[cCellIndex];
                            var pInput = cCell.getElementsByTagName("input")[0];

                            pInput.style.backgroundColor = "#F7FAFF";
                            pInput.value = clipboard_table[row][col];
                        }
                    }
                }
            }

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017