本帖最后由 Mr_Edwin 于 2010-07-18 00:11:18 编辑

解决方案 »

  1.   

    前台只是显示记录:
    导出到excel多是后台的工作。
      

  2.   

    见贴子:
    http://topic.csdn.net/u/20100718/00/5e2d8a59-1fd7-4d6f-a177-1ab0662e80d0.html?seed=1615527988&r=67053762#r_67053762
    前台:JScript code    { text: "导出", icon: "", cls: "x-btn-text-icon", handler: function() { Ext.Msg.show({ title: "提示", msg: "是否导出?", width: 400, icon: Ext.MessageBox.QUESTION, buttons: Ext.MessageBox.YESNO, fn: function(btn) { if (btn === "yes") { var urlParams = Ext.urlEncode(paramsObj); var frm = document.getElementById('frmExcel'); if (frm == null) { frm = document.createElement('iframe'); frm.id = 'frmExcel'; frm.name = id; frm.className = 'x-hidden'; frm.src = ""; document.body.appendChild(frm); } else { frm.src = ""; } } } }) } }
    C# code    部分后台: DataTable dt = new DataTable(); int index = 0; Workbook wb = new Workbook(); List<WorkSheet> wsList = new List<WorkSheet>(); for (int i = 0; i < dt.Rows.Count; i++) { if (index % 60000 == 0) { WorkSheet ws = new WorkSheet(string.Format("11{0}", index % 60000 + 1)); ws.AddColumn("11"); ws.AddColumn("22"); ws.AddColumn("33"); ws.AddColumn("44"); ws.AddColumn("55"); ws.AddColumn("66"); wb.AddWorkSheet(ws); wsList.Add(ws); } object[] datas = new object[6]; DataRow dr = dt.Rows[i]; datas[0] = dr["a"]; datas[1]=dr["b"]; datas[2]=dr["c"]; datas[3] = dr["d"]; datas[4] = dr["e"]; datas[5] = dr["f"]; wsList[index / 60000].WriteRows(datas); index++; } wb.Download("1.xls");
      

  3.   

    后台代码是和底层库有关联
    你按照上面的写就可以了。
    主要能得到dt(DataTable)就可以了
      

  4.   

     string constr = System.Configuration.ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
    string sql=".........";
            DataTable dt = SqlHelper.ExecuteDataset(constr, CommandType.Text, sql).Tables[0];
    现在我得到DataTable了
    我的DataTable如何结合你的后台代码?
      

  5.   

    看哪里的代码?前台的我贴了后台的//---PersonLeadToExcelExcel.ashx--- string constr = System.Configuration.ConfigurationManager.ConnectionString["connStr"].ConnectionString;
     string sql=".........";
      DataTable dt = SqlHelper.ExecuteDataset(constr, CommandType.Text, sql).Tables[0];
     
    就这么多..
    如何结合你的?
      

  6.   


     function PersonnelFile() {
        var common = new BT.common();
        common.clear('centerTabPanel');
        var toptoolbar = new Ext.Toolbar({
            buttons: [ {
                iconCls: 'excel'
                , text: '导出'
                , handler: PersonLeadToExcel
            }
            ]
        });
        //数据源
       var store = new Ext.data.Store({
            proxy: new Ext.data.HttpProxy({ url: 'BTSystemOA/btrlzy/PersonalManagement/SearchPerson.ashx', method: 'POST' }),
            reader: new Ext.data.JsonReader({
                totalProperty: 'totalCount', //总的数据条数
                root: 'data',
                successProperty: 'success'
            }, [
                      { name: 'cEmployeeNo', type: 'string' }
                    , { name: 'cTrueName', type: 'string' }
                    , { name: 'cSex', type: 'string' }
                    , { name: 'cNatives', type: 'string' }
                    , { name: 'cEducation', type: 'string' }
                    , { name: 'cJobName', type: 'string' }
                    , { name: 'cDeptName', type: 'string' }
                    , { name: 'dOnDutyDate', type: 'string' }
                    , { name: 'TPactDate', type: 'string' }
                    , { name: 'FPactDate', type: 'string' }
                    ]
            ),
            remoteSort: true,
            sortInfo: { field: 'cEmployeeNo', direction: 'ASC' },
            autoload: true,
            baseParams: { cEmployeeNo: '', cTrueName: '', cEducation: '', dOnDutyDate: '', cJobName: '', cDeptName: '', cState: '', TPactDate: '', FPactDate: '' }
        });
        
        var PersonnelFile = new Ext.Panel({
            id: 'PersonnelFile'
            , title: '人员档案'
            , autoDestroy: true
            , closable: true
            , layout: 'fit'
            , tbar: toptoolbar
        });
        
        var rowNumber = new Ext.grid.RowNumberer({
            width: 35,
            header: "序号"
        });    //分页工具栏
        var page_toolbar = new BT.ux.PageSizeComboToolbar({
            pageSize: 50,
            store: store
        });
        
        //表格
        var PersonnelGrid = new Ext.grid.GridPanel({
            id: 'PersonnelGrid',
            bodyStyle: 'widht:100%;height:100%;',
            store: store,
            cm: new Ext.ux.grid.LockingColumnModel([rowNumber,
            { header: "人员编码", dataIndex: "cEmployeeNo", sortable: true, width: 100, id: 'index' },
            { header: "姓名", dataIndex: "cTrueName", sortable: true, width: 80 },
            { header: "性别", dataIndex: "cSex", sortable: true, width: 50 },
            { header: "籍贯", dataIndex: "cNatives", sortable: true, width: 100 },
            { header: "学历", dataIndex: "cEducation", sortable: true, width: 50 },
            { header: "岗位名称", dataIndex: "cJobName", sortable: true, width: 150 },
            { header: "部门名称", dataIndex: "cDeptName", sortable: true, width: 150 },
            { header: "入职日期", dataIndex: "dOnDutyDate", sortable: true, width: 150 },
            { header: "合同日期", dataIndex: "TPactDate", sortable: true, width: 150 },
            { header: "合同到期", dataIndex: "FPactDate", sortable: true, width: 150 }
        ]),
    //        view: new Ext.ux.grid.LockingGridView(),
            trackMouseOver: true,
            disableSelection: false,
            loadMask: true,
            autoExpandColumn: 10,
            stripeRows: true,
            bbar: page_toolbar
        });
        PersonnelFile.add(PersonnelGrid);
        Ext.getCmp("centerTabPanel").add(PersonnelFile);
        Ext.getCmp("centerTabPanel").setActiveTab(PersonnelFile);
        Ext.getCmp("centerTabPanel").doLayout();
    }
    //-----------------------------------------------导出Excel-------------------------------------
    function PersonLeadToExcel() {
        Ext.Ajax.request({
            url: "BTSystemOA/btrlzy/PersonLeadToExcel.ashx"
            , async: false
            , method: "POST"
            , params: { cEmployeeNo:Ext.getCmp('cEmployeeNo').getValue(),
                        cTrueName:Ext.getCmp(cTrueName).getValue(),
                        cEducation:  Ext.getCmp(cEducation).getValue()
                       }
           });}这是前台.js文件[/code]