Search code examples
jqueryhtmlexceljqgridexport-to-excel

jQGrid Number to text while Export to Excel


I am using jqgrid 5.3.2

This is My Function which get the data server

function GetReportData(gridData) {
            var grid_selector = "#DeliveryStatusReportGrid";
            var pager_selector = "#DeliveyStatusReportpager_list_1";

            $(grid_selector).jqGrid({
                data: gridData,
                datatype: "local",
                height: 400,
                autowidth: true,
                shrinkToFit: true,
                rowNum: 13,
                rowList: [10, 20, 30],
                colNames: ['Code', 'CardAccountNo'],
                colModel: [
                { name: 'Code', width: 10, key: true, align: 'center', hidden: true },

                { name: 'Card_Number', width: 1000, index: 'Card_Number', width: 20, search: true, align: 'center' },
                ],
                pager: pager_selector,
                viewrecords: true,
                caption: "Customer Gift Report",
                hidegrid: false,
                loadComplete: function () {
                    $(grid_selector).jqGrid('setGridWidth', $(grid_selector).closest(".jqgrid").width());
                    jQuery(grid_selector).trigger('resize');
                }
            }).trigger('reloadGrid', [{ page: 1 }]);
        }

This is my export to excel

$("#exportToExcel").on("click", function () {
            $("#DeliveryStatusReportGrid").jqGrid("exportToExcel", {
                includeLabels: true,
                includeGroupHeader: true,
                includeFooter: true,
                fileName: "DeliveryStatus.xlsx",
                maxlength: 40 // maxlength for visible string data
            })
        })

But when i export to excel My number changes For ex - 5402760000484016 to 5402760000484010 Excel Number Formatting Issue So i want to convert my number to text so that it does not change or formats while Export to Excel using Jqgrid Any Help is Thankful


Solution

  • This is actually a problem in excel, which can't handle a numbers over 15 digits. You can read more on this problem here

    We have take care about this problem and have fixed it setting the number to be displayed as string when they are > 15 digits. If you are a licensed user, please let us know and we will send you the fix.

    The problem can be solved with the current release using the custom formatter, where when the values is exported to excel to add to it a space at end of the value.

    { name: 'Card_Number', 
        width: 1000, 
        index: 'Card_Number', 
        width: 20, 
        search: true, 
        align: 'center',
        formatter : function ( value, options, rdata) {
            if( options.exporttype === "excel") {
                return value+' ';
            } else {
                return value;
            }
        }
     }