
前端mgr.js
1 do_exportsv: function () { 2 var win = this; 3 var fd = new ActiveXObject("MSComDlg.CommonDialog"); 4 fd.Filter = "Excel文档|*.xlsx"; 5 fd.FilterIndex = 1; 6 fd.MaxFileSize = 128; 7 fd.ShowSave();//這個是儲存的對話框,如果是需要打開的話,就要用fd.ShowOpen() 8 if (fd.filename == '') { 9 return; 10 } 11 Ajax_request("Data.aspx?cmd=do_exportsv", { filename: fd.filename }, win.on_exportsv, win);//获取要保存文件的全路径 12 }, 13 on_exportsv: function (sender, data) { 14 //sender.store.reload(); 15 messagebox_show(data); 16 }, 17 18 19 tbar: ['-', { 20 text: "增加", 21 iconCls: "icon-add", 22 handler: function () { this.ownerCt.ownerCt.do_add() } 23 }, '-', { 24 text: "刷新", 25 iconCls: "icon-refresh", 26 handler: function () { this.ownerCt.ownerCt.do_refresh() } 27 }, '-', { 28 text: "导出", 29 iconCls: "icon-exportsv", 30 handler: function () { this.ownerCt.ownerCt.do_exportsv() } 31 }, '-'],
后端Data.aspx.cs
1 protected void do_exportsv() 2 { 3 string path_filename = Pub.read_param(Request, "filename"); 4 DBSQLite.DataConn conn = new DBSQLite.DataConn(); 5 string sql = "select * from servicelist"; 6 DataTable dt = DBSQLite.DataConn.select(DBSQLite.DataConn.currdb, sql); 7 dt.Columns.Add("filename", typeof(string)); 8 foreach (DataRow dr in dt.Rows) 9 { 10 dr["filename"] = get_asmx_filename(DBUtils.get_str(dr, "servicename") + ".asmx"); 11 } 12 13 if (null == dt || dt.Rows.Count <= 0) return; 14 15 string content = "服务名,服务地址,服务描述,节点注册地址,节点注册时间\n"; 16 // 保存数据 17 for (int r = 0; r < dt.Rows.Count; r++) 18 { 19 20 content += dt.Rows[r]["servicename"].ToString() + ","; 21 content +="http://localhost:80/ESB/service/"+ dt.Rows[r]["servicename"].ToString() + ".asmx,"; 22 content += dt.Rows[r]["servicedescription"].ToString() + ","; 23 content += dt.Rows[r]["app_url"].ToString() + ","; 24 content += dt.Rows[r]["app_url_reg_time"].ToString() + ","; 25 26 content += "\n"; 27 //rowRead++; 28 //percent = ((float)(100 * rowRead)) / totalCount; // 当前进度 29 } 30 System.IO.File.WriteAllText(path_filename.Replace(".xlsx",".csv"),content.Remove(content.LastIndexOf("\n")),Encoding.UTF8); 31 string msg = "导出数据成功!"; 32 Response.Write(Pub.make_json(msg)); 33 34 }