导出后台调用

来源:互联网 发布:易语言磁力链解析源码 编辑:程序博客网 时间:2024/06/01 08:28
/// /// 导出按钮功能 /// 2011/1/17 limm add /// /// /// protected void btnExport_Click(object sender, EventArgs e) { try { DataSet dsNew = new DataSet(); string templetFilePath = Server.MapPath("../temp/开发区发展建设情况表(季报).xls"); string outputFilePath = Server.MapPath("../excel/开发区发展建设情况表(季报).xls"); string sheetName = "开发区发展建设情况表(季报)"; String id = Request.QueryString["id"].ToString(); //取出id DataSet ds = styj.QueryExpData(id); // DataSet ds = styj.ViewTitleDetaile(Request.QueryString["LID"].ToString()); int Colcount = ds.Tables[0].Columns.Count; //判断列数是否大于0 if (Colcount > 0) { dsNew.Tables.Add();//添加一个数据表 dsNew.Tables[0].Columns.Add();//添加一列 //循环将数据赋给新的dataset for (int i = 0; i < Colcount; i++) { dsNew.Tables[0].Rows.Add();//增加一行 dsNew.Tables[0].Rows[i][0] = ds.Tables[0].Rows[0][i].ToString(); } } int count = dsNew.Tables[0].Rows.Count; ExcelHelper outputExcel = new ExcelHelper(templetFilePath, outputFilePath); string[] hAlignmentFlg = new string[count]; //设置对齐方式 for (int i = 0; i < count; i++) { hAlignmentFlg[i] = "1";//右对齐 } outputExcel.DataTableToExcel(dsNew, count, 3, 3, count, false, sheetName, hAlignmentFlg); bool success = ResponseFile(Page.Request, Page.Response, "开发区发展建设情况表(季报).xls", outputFilePath, 1024000); if (!success) Page.ClientScript.RegisterStartupScript(Page.GetType(), "", ""); } }
原创粉丝点击