zoukankan      html  css  js  c++  java
  • EXcel

    #region 生成Excel文件

                FileStream fsExcel = null;
                StreamWriter swExcel = null;

                string excelPath = Request.PhysicalApplicationPath + ExportSeqNo + ".xls";

                if (File.Exists(excelPath))
                {
                    File.Delete(excelPath);
                }
                fsExcel = new FileStream(excelPath, FileMode.CreateNew, FileAccess.ReadWrite);
                swExcel = new StreamWriter(fsExcel);
                swExcel.WriteLine("<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">");
                swExcel.WriteLine("<head>");
                swExcel.WriteLine("<!--[if gte mso 9]>");
                swExcel.WriteLine("<xml>");
                swExcel.WriteLine(" <x:ExcelWorkbook>");
                swExcel.WriteLine("   <x:ExcelWorksheets>");
                swExcel.WriteLine("    <x:ExcelWorksheet>");
                swExcel.WriteLine("     <x:Name>手机充值表</x:Name>");
                swExcel.WriteLine("     <x:WorksheetOptions>");
                swExcel.WriteLine("       <x:Print>");
                swExcel.WriteLine("        <x:ValidPrinterInfo />");
                swExcel.WriteLine("       </x:Print>");
                swExcel.WriteLine("     </x:WorksheetOptions>");
                swExcel.WriteLine("    </x:ExcelWorksheet>");
                swExcel.WriteLine("   </x:ExcelWorksheets>");
                swExcel.WriteLine("</x:ExcelWorkbook>");
                swExcel.WriteLine("</xml>");
                swExcel.WriteLine("<![endif]-->");
                swExcel.WriteLine("</head>");
                swExcel.WriteLine("<body>");
                swExcel.WriteLine("<table style='text-align:center;'>");
                swExcel.WriteLine(" <tr>");
                swExcel.WriteLine("   <td><strong>序号(订单号)</strong></td>");
                swExcel.WriteLine("   <td><strong>UID</strong></td>");
                swExcel.WriteLine("   <td><strong>手机号</strong></td>");
                swExcel.WriteLine("   <td><strong>充值金额</strong></td>");
                swExcel.WriteLine("   <td><strong>状态</strong></td>");
                swExcel.WriteLine("   <td><strong>提现日期</strong></td>");
                swExcel.WriteLine(" </tr>");
                foreach (DataRow dr in dt.Rows)
                {
                    string status = EnumHelper.GetEnumDescriptionByValue<Payment.CouponAccount.Model.Common.Enums.PayOutChangeStatusEnum>(Convert.ToInt32(dr["PayStatus"].ToString().Trim()));
                    swExcel.WriteLine(" <tr>");
                    swExcel.WriteLine("   <td style='vnd.ms-excel.numberformat:@;'>" + dr["ID"].ToString().Trim() + "</td>");
                    swExcel.WriteLine("   <td>" + dr["UID"].ToString().Trim() + "</td>");
                    swExcel.WriteLine("   <td>" + dr["Mobile"].ToString().Trim() + "</td>");
                    swExcel.WriteLine("   <td style='vnd.ms-excel.numberformat:@;'>" + dr["Amount"].ToString().Trim() + "</td>");
                    swExcel.WriteLine("   <td>" + status + "</td>");
                    swExcel.WriteLine("   <td>" + dr["PayOutTime"].ToString().Trim() + "</td>");
                    swExcel.WriteLine(" </tr>");
                }
                swExcel.WriteLine("</table>");
                swExcel.WriteLine("</body>");
                swExcel.WriteLine("</html>");
                swExcel.Dispose();
                fsExcel.Dispose();

                byte[] excelBuffer = File.ReadAllBytes(excelPath);
                //删除Excel文件
                File.Delete(excelPath);

                Response.Clear();
                Response.Charset = "utf-8";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + ExportSeqNo + ".xls");
                Response.ContentType = "application/ms-excel";
                Response.ContentEncoding = System.Text.Encoding.UTF8;
                Response.HeaderEncoding = System.Text.Encoding.UTF8;
                Response.BinaryWrite(excelBuffer);

  • 相关阅读:
    css 去除input框边框 鼠标禁用状态 背景颜色
    css 文字边框
    搭建简易的Vue项目
    那些年遇到的Bug
    vue 点击弹出下拉菜单 点击其他页面收回菜单
    css 控制文本显示
    css tips提示框 三角形 + 框
    vue 细节 规范(只要不断片,持续的更新.....)
    @click.self
    工欲善其事,必先利其器
  • 原文地址:https://www.cnblogs.com/qianlong/p/2744621.html
Copyright © 2011-2022 走看看