zoukankan      html  css  js  c++  java
  • 解决:下载EXCEL文件,自动用迅雷下载aspx

    解决:下载EXCEL文件,自动用迅雷下载aspx

    if
    (Request.QueryString["id"] != null && !string.IsNullOrEmpty(Request.QueryString["id"].ToString())) { if (Request.QueryString["oid"] != null && !string.IsNullOrEmpty(Request.QueryString["oid"].ToString())) { id = Request.QueryString["id"].ToString(); oid = Request.QueryString["oid"].ToString(); string sqlWhere = string.Format("PProductNumber='{0}' and OrdersNumber='{1}'", id, oid); List<SonOrders> li= _SonOrdersManager.GetOrdersLists(sqlWhere); if (li.Count > 0&&li!=null) { MemoryStream ms = new MemoryStream(); IWorkbook workbook = new HSSFWorkbook(); ISheet sheet = workbook.CreateSheet(); ICellStyle style1 = workbook.CreateCellStyle(); IFont font = workbook.CreateFont(); font.FontHeightInPoints = 11; style1.SetFont(font); sheet.DefaultRowHeight = 25 * 20; for (int i = 0; i < 9; i++) { if (i == 0) sheet.SetColumnWidth(i,28 * 256); else sheet.SetColumnWidth(i, 23 * 256); sheet.SetDefaultColumnStyle(i, style1); } IRow row1 = sheet.CreateRow(0); ICell cell = row1.CreateCell(0); cell.SetCellValue(oid+"_状态详细"); ICellStyle style2 = workbook.CreateCellStyle(); style2.Alignment = HorizontalAlignment.CENTER; IFont font2 = workbook.CreateFont(); font2.FontHeight = 20 * 20; style2.SetFont(font2); cell.CellStyle = style2; sheet.AddMergedRegion(new CellRangeAddress(0, 0, 0, 7)); IRow headerRow = sheet.CreateRow(1); headerRow.CreateCell(0).SetCellValue("产品编号"); headerRow.CreateCell(1).SetCellValue("下单时间"); headerRow.CreateCell(2).SetCellValue("原型验收时间"); headerRow.CreateCell(3).SetCellValue("首件验收时间"); headerRow.CreateCell(4).SetCellValue("组装验收时间"); headerRow.CreateCell(5).SetCellValue("厂家出库时间"); headerRow.CreateCell(6).SetCellValue("现场入库时间"); headerRow.CreateCell(7).SetCellValue("领用入库时间"); headerRow.CreateCell(8).SetCellValue("开箱验收时间"); headerRow.CreateCell(9).SetCellValue("安装完成时间"); headerRow.CreateCell(10).SetCellValue("安装验收时间"); int j = 2; foreach (SonOrders so in li) { IRow dataRow = sheet.CreateRow(j++); dataRow.CreateCell(0).SetCellValue(so.SProductNumber); dataRow.CreateCell(1).SetCellValue(GetTimeS("下单时间", so.SProductNumber).ToString()); dataRow.CreateCell(2).SetCellValue(GetTimeS("原型验收时间", so.SProductNumber).ToString()); dataRow.CreateCell(3).SetCellValue(GetTimeS("首件验收时间", so.SProductNumber).ToString()); dataRow.CreateCell(4).SetCellValue(GetTimeS("组装验收时间", so.SProductNumber).ToString()); dataRow.CreateCell(5).SetCellValue(GetTimeS("厂家出库时间", so.SProductNumber).ToString()); dataRow.CreateCell(6).SetCellValue(GetTimeS("现场入库时间", so.SProductNumber).ToString()); dataRow.CreateCell(7).SetCellValue(GetTimeS("领用入库时间", so.SProductNumber).ToString()); dataRow.CreateCell(8).SetCellValue(GetTimeS("开箱验收时间", so.SProductNumber).ToString()); dataRow.CreateCell(9).SetCellValue(GetTimeS("安装完成时间", so.SProductNumber).ToString()); dataRow.CreateCell(10).SetCellValue(GetTimeS("安装验收时间", so.SProductNumber).ToString()); } workbook.Write(ms); ms.Flush(); ms.Position = 0; try { string[] files = Directory.GetFiles(System.AppDomain.CurrentDomain.BaseDirectory + "excels/"); foreach (string file in files) { File.Delete(file); } } catch (Exception exx) { Response.Write(exx.Message.ToString()); } string pname = "状态详细_" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls"; NpoiHelper.SaveToFile(ms, System.AppDomain.CurrentDomain.BaseDirectory + "excels/" + pname); Response.Redirect("~/excels/" + pname, false); Response.Clear(); // Response.Clear(); // Response.ClearHeaders(); // Response.Buffer = false; // Response.ContentType = "application/octet-stream"; // if (Request.Browser.Browser == "Firefox") // System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + oid + "_状态详细.xls"); //else // System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(oid + "_状态详细.xls", System.Text.Encoding.UTF8)); // System.Web.HttpContext.Current.Response.AppendHeader("Content-Length", ms.Length.ToString()); // System.Web.HttpContext.Current.Response.BinaryWrite(ms.GetBuffer()); // System.Web.HttpContext.Current.Response.Flush(); // System.Web.HttpContext.Current.Response.End(); } }
  • 相关阅读:
    自定义View的ToolBar布局报错Error:(2) No resource identifier found for attribute 'context' in package 'c
    在学git之主分支 branch
    获取发布版SHA1
    关于开启线程与UI的操作
    播放音频和视频(VideoView控件)
    通知栏Notification的应用
    Android 真机调式 Installation failed with message 远程主机强迫关闭了一个现有的连接。. It is possible that this issue is resolved by uninstalling an existing version of the apk if it is present, and then re-installing. WA
    运行程序申请危险权限
    mysql乐观锁总结和实践
    Nginx配置文件nginx.conf中文详解
  • 原文地址:https://www.cnblogs.com/w519/p/4228630.html
Copyright © 2011-2022 走看看