Beispiel #1
0
        /// <summary>
        /// 充值导出excel
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public FileResult ExportExcelForRech(string mobile = "", string suite = "-1", string platform = "全部", string starttime = "", string endtime = "")
        {
            StringBuilder strb = new StringBuilder();

            strb.Append(" where 1=1 ");
            if (mobile != "")
            {
                strb.Append(" and a.account like '" + mobile + "%' ");
            }
            if (suite != "-1")
            {
                strb.Append(" and a.vossuiteid = " + suite + " ");
            }
            if (platform != "全部")
            {
                strb.Append(" and a.platform = '" + platform + "' ");
            }
            if (starttime != "" && endtime != "")
            {
                strb.Append(" and (convert(varchar(10),a.paytime,120) between '" + starttime + "' and '" + endtime + "')");
            }
            strb.Append(" order by a.addtime desc ");
            DataTable dt = Recharge.GetRechargeListForDt(1, -1, strb.ToString());

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

            listcol["编号"]   = "rechargeid"; listcol["手机号"] = "account"; listcol["姓名"] = "nickname"; listcol["职位"] = "userrank"; listcol["充值金额"] = "total_fee";
            listcol["充值套餐"] = "suitename";
            listcol["支付方式"] = "platform"; listcol["充值时间"] = "paytime";

            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");
        }