Extjs gridPanel导出Excel 如何实现?(WebForm) 本帖最后由 Mr_Edwin 于 2010-07-18 00:11:18 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 前台只是显示记录:导出到excel多是后台的工作。 见贴子: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"); 后台代码是和底层库有关联你按照上面的写就可以了。主要能得到dt(DataTable)就可以了 string constr = System.Configuration.ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;string sql="........."; DataTable dt = SqlHelper.ExecuteDataset(constr, CommandType.Text, sql).Tables[0];现在我得到DataTable了我的DataTable如何结合你的后台代码? 看哪里的代码?前台的我贴了后台的//---PersonLeadToExcelExcel.ashx--- string constr = System.Configuration.ConfigurationManager.ConnectionString["connStr"].ConnectionString; string sql="........."; DataTable dt = SqlHelper.ExecuteDataset(constr, CommandType.Text, sql).Tables[0]; 就这么多..如何结合你的? 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] ie下求div的绝对边距有误,求解 求助 JS怎么获取iframe的元素(iframe链接的是别的网站的页面) 像baidu那种在文本框中输入内容后,会自动检索相应内容的效果怎么实现? 有三个按扭,点击按扭三设,按扭一为不可用,按扭二为可用。 求一正则表达式 匹配文章内容中 所有 带超链接的图片 我怎么取得到服务器的时间,日期,星期呢? 请问如何把unicode码,变成对应的字符 天啊。。~~~经验。。。~~~ 关于php中嵌套的js,没有正常执行的问题,请大家帮忙看看 JScript闭包 究竟用不用 VS2010开发html5问题
导出到excel多是后台的工作。
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");
你按照上面的写就可以了。
主要能得到dt(DataTable)就可以了
string sql=".........";
DataTable dt = SqlHelper.ExecuteDataset(constr, CommandType.Text, sql).Tables[0];
现在我得到DataTable了
我的DataTable如何结合你的后台代码?
string sql=".........";
DataTable dt = SqlHelper.ExecuteDataset(constr, CommandType.Text, sql).Tables[0];
就这么多..
如何结合你的?
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]