This is a migrated thread and some comments may be shown as answers.

Paste from Excel stopped working

6 Answers 43 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
Iron
Iron
Veteran
David asked on 07 Jul 2016, 12:48 PM

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];
                    }
                }
            }
        }

6 Answers, 1 is accepted

Sort by
0
David
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 18 Jul 2016, 05:32 PM
Any help?
0
Konstantin Dikov
Telerik team
answered on 21 Jul 2016, 07:17 AM
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.
0
David
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 21 Jul 2016, 02:27 PM

Hi Konstantin,

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

   Picture attached

0
David
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 29 Jul 2016, 05:23 PM

Konstantin,

   Any recommendations?

0
David
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 22 Aug 2016, 02:37 PM

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];
                    }
                }
            }
        }

0
David
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 22 Aug 2016, 02:43 PM

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];
                    }
                }
            }
        }

Tags
Grid
Asked by
David
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
David
Top achievements
Rank 1
Iron
Iron
Veteran
Konstantin Dikov
Telerik team
Share this question
or