导入导出excel表

1.js使用datagrid时:

rownumbers:true 显示序号
frozenColumns:[[]] 冻结某些列
例如:

 var $oneKeyAlarmHistorygrid;
    $(function () {
        $oneKeyAlarmHistorygrid = $("#oneKeyAlarmHistory-dg").datagrid({
            method: "GET",
            url: "${pageContext.request.contextPath}/oneKeyAlarmHistory/oneKeyAlarmHistoryList",
            width: '100%',
            pagination: true,
            rownumbers: false,
            border: true,
            striped: true,
            singleSelect: true,
            pageList: [10, 20, 30, 40, 50],
            frozenColumns:[[
                {field: 'companyName2', title: '操作', width: '13%', align: 'center', sortable: false, formatter: oneKeyAlarmHistoryOptionButton},
            ]],
            columns: [[{field: 'id', title: 'id', width: '30%', sortable: false, hidden: true},
                {field: 'alarmType', title: '报警类型', width: '5%', sortable: false},
                {field: 'customerPhone', title: '乘客手机号', width: '8%', sortable: false},
                {field: 'carUserPhone', title: '司机手机号', width: '8%', sortable: false},
                {field: 'carUserName', title: '司机姓名', width: '5%', sortable: false},
                {field: 'orderId', title: '订单号', width: '16%', sortable: false},
                {field: 'alarmAddress', title: '报警时地址', width: '25%', sortable: false},
                {field: 'alarmMsg', title: '报警短信内容', width: '25%', sortable: false},
                {field: 'alarmDate', title: '报警时间', width: '14%', sortable: false},
                {field: 'isHandle', title: '状态', width: '5%', sortable: false,formatter:function(value){
                        if(value==0||value=="0"){
                            return "未处理";
                        }else if(value==1||value=="1"){
                            return "已处理";
                        }
                    }},
                {field: 'updateName', title: '处理人', width: '5%', sortable: false},
                {field: 'remarks', title: '处理意见', width: '10%', sortable: false},
                {field: 'updateTime', title: '处理时间', width: '14%', sortable: false}
            ]], toolbar: '#oneKeyAlarmHistorytb',
            onHeaderContextMenu: function (e, field) {
                e.preventDefault();
                if (!oneKeyAlarmHistoryCmenu) {
                    oneKeyAlarmHistoryCreateColumnMenu();
                }
                oneKeyAlarmHistoryCmenu.menu('show', {
                    left: e.pageX,
                    top: e.pageY
                });
            },
            onLoadSuccess: function (data) {
                $oneKeyAlarmHistorygrid.datagrid('resize', {
                   height: $(window).height()-$("#oneKeyAlarmHistory-search").height()-105
                });
                $('.button-delete').linkbutton({});
                $('.button-edit').linkbutton({});
            }
        });
    });

2.导入excel表格

html文件:

js文件:
  /*点击上传*/
    function cilckImport() {
        $("#avatsel1").click(function(){
            $("#uploadToImportFile").trigger('click');
        });
        $("#uploadToImportFile").change(function(){
            $("#uploadToImportFile").val($(this).val());
        });
    }
  /*上传excel文件*/
    var AllXlsExt=".xls|.xlsx|"//全部图片格式类型
    function contactAjaxXlsUpload(){
        var fileName=$("#uploadToImportFile").filebox('getValue');
        var FileExt=fileName.substr(fileName.lastIndexOf(".")).toLowerCase();
        if(fileName.trim()==""){
            alert("请选择excel文件");
            return;
        }
        if(AllXlsExt.indexOf(FileExt+"|") ==-1){
            alert("请选择xls,xlsx格式的文件");
            return;
        }
        //当文件正在上传时,弹出正在加载的弹出框,防止多次上传图片
        load();
        $.ajaxFileUpload({
            url:"${pageContext.request.contextPath}/couponsSend/uploadXls2.action",
            secureuri:false,                       //是否启用安全提交,默认为false
            fileElementId:"avatsel1",           //文件选择框的id属性
            dataType:'text',                       //服务器返回的格式,可以是json或xml等
            success:function(result){        //服务器响应成功时的处理函数
                var result = eval('(' + result + ')');
                if(result.status=="true"){
                    $.messager.alert('提示',"成功导入 "+result.data.successNum+" 条数据");
                    $("#customerPhones").textbox("setValue", result.data.msg);
                }else {
                    $("#importFailedTable").html("失败序号:失败原因");
                    uploadExcelStatus = 1;
                    if (result.data.numsList != null) {
                        $("#ifShow").val(1);
                        $.each(result.data.numsList, function (commentIndex, comment) {
                            var importFailedTable = $("#importFailedTable");
                            var tr = "" + commentIndex + "" + comment + "";
                            importFailedTable.append(tr);
                        });
                        $("#couponSend-dd").dialog({
                            modal: true,
                            minimizable: false,//最小化,默认false
                            maximizable: false, //最大化,默认false
                            collapsible: false, //可折叠,默认false
                            resizable: true  //可缩放,即可以通脱拖拉改变大小,默认false
                        }).dialog("open").dialog('setTitle', '导入失败详情');
                        $("#couponSend-dd").show();
                        couponsSendDialog.dialog('close');
                    }
                }
            }
        });
    }

jQuery.extend({
createUploadIframe: function(id, uri) {
        //create frame
        var frameId = 'jUploadFrame' + id;
        var iframeHtml = '