【问题标题】:Exporting Grid data to excel将网格数据导出到 Excel
【发布时间】:2014-03-14 11:08:34
【问题描述】:

我是 jq 网格的新手,得到了一些代码来绑定数据。在互联网的帮助下,我能够绑定数据,但我可以选择将导出按钮添加到网格,该按钮可以将网格的当前数据导出到 Excel。有很多代码可用,但我没有以正确的方式得到它。请指导我..

 var bindReports = function () {
                $('#list1').jqGrid('GridUnload');
                $("#list1").jqGrid({
                    url: "GetReportDetails",
                    postData: { startDate: $('#startDate').val(), endDate: $('#endDate').val(), ins_Type: $("#InsuranceType").val(), ass_Clincian: $("#ddlAssignedClician").val() },
                    datatype: "json",
                    mtype: "POST",
                    colNames: ["ID", "First Name", "Last Name", "Date Of Birth", "Date of Intake", "Insurance Type", "Insurance company", "Assigned Clinician"],
                    colModel: [
                            { name: "ID", index: "ID", hidden: true, key: true },
                            { name: "FirstName", index: "FirstName", width: 40, align: "left", sortable: true, formatter: 'showlink', formatoptions: { baseLinkUrl: 'javascript:', showAction: "Link('", addParam: "');" } },
                            { name: "LastName", index: "LastName", width: 40, align: "left", sortable: true, formatter: 'showlink', formatoptions: { baseLinkUrl: 'javascript:', showAction: "Link('", addParam: "');" } },
                            { name: "DOB", index: "DOB", width: 40, align: "left", formatter: 'date', sorttype: "date", sortable: true },
                            { name: "DOI", index: "DOI", width: 40, align: "left", formatter: 'date', sorttype: "date", sortable: true },
                            { name: "IT", index: "IT", width: 40, align: "left", sortable: true },
                            { name: "IC", index: "IC", width: 50, align: "left", sortable: true },
                            { name: "AC", index: "AC", width: 50, align: "left", sortable: true }],
                    // Grid total width and height
                    //multiselect: true, for checkboxes in first column to select 
                    rowNum: 20,
                    rowList: [5, 10, 15, 20],
                    width: 900,
                    height: "100%",
                    // Paging
                    pager: $("#pager1"),
                    viewrecords: true,

                    // Default sorting
                    //sortname: "FirstName",
                    sortorder: "asc",
                    sortable: true,
                    loadonce: true,
                    hidegrid: false,
                    // Grid caption
                    caption: "Reports List"
                }).navGrid("#pager1", { refresh: false, add: false, edit: false, del: false }, {}, // settings for edit
                                                                                              {}, // settings for add
                                                                                              {}, // settings for delete
                                                                                              { sopt: ["cn"] } // Search options. Some options can be set on column level
                    );
            }

【问题讨论】:

    标签: .net asp.net-mvc-3 asp.net-mvc-4 jqgrid jqgrid-asp.net


    【解决方案1】:

    Excel 导入有不同的实现方法。有人从网格中获取数据并将其发送到服务器,然后服务器生成 Excel 并将其返回。在我看来,最好不要向服务器发送任何额外的数据。而不是服务器应该直接生成基于postData 的 Excel 导入。 The answer 演示了如何生成 XLSX 文件,another answer 为演示提供了 ASP.NET MVC 中的导出实现。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 2015-12-07
      • 1970-01-01
      • 2013-02-19
      相关资源
      最近更新 更多