Example #1
0
        /// <summary>
        /// 提现导出excel
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public FileResult ExportExcel(string username = "", string mobile = "", string alipayaccount = "", string status = "")
        {
            StringBuilder strb = new StringBuilder();

            strb.Append(" where 1=1 ");
            if (username != "")
            {
                strb.Append(" and a.username like '%" + username + "%' ");
            }
            if (mobile != "")
            {
                strb.Append("  and a.mobile like '" + mobile + "%' ");
            }
            if (alipayaccount != "")
            {
                strb.Append(" and a.alipay like '" + alipayaccount + "%' ");
            }
            if (status != "-1")
            {
                strb.Append(" and a.state =" + status);
            }

            strb.Append(" order by a.[addtime] desc");

            //编号、手机号、姓名、支付宝账号、提现金额、提现时间、状态(审核中、已完成)、异常信息(支持文本输入)
            DataTable dt = Recharge.GetDrawListForDT(1, -1, strb.ToString());

            Dictionary <string, string> listcol = new Dictionary <string, string>()
            {
            };

            listcol["编号"]   = "drawid"; listcol["手机"] = "mobile"; listcol["姓名"] = "username"; listcol["支付宝账号"] = "alipay"; listcol["提现金额"] = "money";
            listcol["提现时间"] = "addtime";
            listcol["状态"]   = "state"; listcol["异常信息"] = "exception";

            string html = ExcelHelper.BuildHtml(dt, listcol);


            //第一种:使用FileContentResult
            byte[] fileContents = Encoding.Default.GetBytes(html);
            return(File(fileContents, "application/ms-excel", "提现信息" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls"));

            ////第二种:使用FileStreamResult
            //var fileStream = new MemoryStream(fileContents);
            //return File(fileStream, "application/ms-excel", "fileStream.xls");

            ////第三种:使用FilePathResult
            ////服务器上首先必须要有这个Excel文件,然会通过Server.MapPath获取路径返回.
            //var fileName = Server.MapPath("~/Files/fileName.xls");
            //return File(fileName, "application/ms-excel", "fileName.xls");
        }