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