如何修复JqGrid exportToExcel无效的xml错误?

时间:2017-02-23 08:46:45

标签: c# jquery asp.net jqgrid asp.net-web-api2

每次尝试导出 jqGrid 的内容时,都会失败并显示以下错误:

Uncaught Error: Invalid XML: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="http:?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/></Relationships>
at Function.error (jquery-1.10.2.js:530)
at Function.parseXML (jquery-1.10.2.js:610)
at HTMLTableElement.<anonymous> (jquery.jqGrid.min.js:1513)
at Function.each (jquery-1.10.2.js:671)
at init.each (jquery-1.10.2.js:280)
at init.exportToExcel (jquery.jqGrid.min.js:1483)
at init.$.fn.jqGrid (jquery.jqGrid.min.js:101)
at <anonymous>:1:22

来自我的网格的数据来自使用 ASP.NET MVC5

构建的 Web API

以下是我的网格和导出按钮的代码段:

$('#myGrid').jqGrid({
        url: '/api/Remittance/GetRemittance',
        mtype: 'GET',
        datatype: 'json',
        styleUI: 'Bootstrap',
        colModel: [
            { key: true, hidden: true, label: 'Id', name: 'Id', width: 300 },
            { label: 'System Source', name: 'System_Source', width: 150 },
            { label: 'Placement Ref', name: 'Placement_Ref', width: 200 },
            { label: 'Transmittal Date', name: 'Transmittal_Date', width: 150, formatter: 'date', formatoptions: { newformat: 'm/d/Y' } },
            { label: 'Transmittal Reference', name: 'Transmittal_Reference', width: 200 },
            { label: 'Transmittal Notes', name: 'Transmittal_Notes', width: 200 },
            { label: 'Doc Transaction Id', name: 'Doc_Transaction_Id', width: 150 },
            { label: 'Doc Transaction Type', name: 'Doc_Transaction_Type', width: 170 },
            { label: 'Doc Status', name: 'Doc_Status', width: 150 },
            { label: 'Doc Date', name: 'Doc_Date', width: 150, formatter: 'date', formatoptions: { newformat: 'm/d/Y' } },
            { label: 'Doc Reference', name: 'Doc_Reference', width: 200 },
            { label: 'Doc Order Reference', name: 'Doc_Order_Reference', width: 200 },
            { label: 'Doc From', name: 'Doc_From', width: 200 },
            { label: 'Doc To', name: 'Doc_To', width: 200 },
            { label: 'Doc Sales Representative', name: 'Doc_Sales_Representative', width: 200 },
            { label: 'Doc Sales/Supply Unit', name: 'Doc_Sales_Supply_Unit', width: 200 },
            { label: 'Doc Amount', name: 'Doc_Amount', width: 150, formatter: 'currency', formatoptions: { decimalSeparator: '.', thousandsSeparator: ',', decimalPlaces: 2 } },
            { label: 'Doc Deductions', name: 'Doc_Deductions', width: 150, formatter: 'currency', formatoptions: { decimalSeparator: '.', thousandsSeparator: ',', decimalPlaces: 2 } },
            { label: 'Doc Gross Amount', name: 'Doc_Gross_Amount', width: 150, formatter: 'currency', formatoptions: { decimalSeparator: '.', thousandsSeparator: ',', decimalPlaces: 2 } }
        ],
        autoWidth: false,
        shrinkToFit: false,
        viewrecords: true,
        emptyrecords: 'No records to display.',
        width: $(this).parent().width(),
        height: 375,
        rowNum: 10,
        pager: '#pagerGrid',
        jsonReader: {
            root: 'rows',
            page: 'page',
            total: 'total',
            records: 'records',
            Id: '0'
        }
        
        $('#exportGrid').click(function () {
        var today = new Date();
        var dd = today.getDate();
        var mm = today.getMonth() + 1; 
        var yyyy = today.getFullYear();

        $('#myGrid').jqGrid('exportToExcel', {
            includeLabels: true,
            includeGroupHeader: true,
            includeFooter: true,
            fileName: 'Remittance_' + mm + '-' + dd + '-' + yyyy + '.xlsx',
            maxlength: 40
        });
    });

1 个答案:

答案 0 :(得分:0)

只使用jquery.jqGrid.js(没有min版本)。它应该工作。我也有同样的问题。它现在有效