惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 司徒正美
Google Online Security Blog
Google Online Security Blog
博客园_首页
量子位
大猫的无限游戏
大猫的无限游戏
酷 壳 – CoolShell
酷 壳 – CoolShell
The Cloudflare Blog
Vercel News
Vercel News
GbyAI
GbyAI
Y
Y Combinator Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
C
Cisco Blogs
IT之家
IT之家
A
Arctic Wolf
P
Privacy International News Feed
G
GRAHAM CLULEY
腾讯CDC
Microsoft Security Blog
Microsoft Security Blog
Microsoft Azure Blog
Microsoft Azure Blog
美团技术团队
T
The Blog of Author Tim Ferriss
AWS News Blog
AWS News Blog
A
About on SuperTechFans
P
Proofpoint News Feed
I
Intezer
月光博客
月光博客
Cloudbric
Cloudbric
Google DeepMind News
Google DeepMind News
T
Tor Project blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
www.infosecurity-magazine.com
www.infosecurity-magazine.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Securelist
Engineering at Meta
Engineering at Meta
爱范儿
爱范儿
F
Full Disclosure
V2EX - 技术
V2EX - 技术
Last Week in AI
Last Week in AI
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
人人都是产品经理
人人都是产品经理
C
Check Point Blog
I
InfoQ
S
Security Affairs
Simon Willison's Weblog
Simon Willison's Weblog
P
Palo Alto Networks Blog
F
Fortinet All Blogs
S
Security @ Cisco Blogs
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
K
Kaspersky official blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security

博客园 - 沸石

快速压缩log文件 SQL Server-拆分字符串返回表(存储过程) SQL Server-动态Pivot表的存储过程 突破AD查询1000条限制(转) 轻松创建运行命令 (转) (转)Resolving errors creating a Strong Name Key 以动词开头的习惯搭配:转 枚举的遍历和字符串转枚举,枚举转字符串 转 - 沸石 - 博客园 (转)英语信件中最常用精选句式 控件命名 转:C#委托及事件 转:关于HttpHandlers和HttpModules的不同 js:scrollLeft,scrollWidth,clientWidth,offsetWidth完全详解 商业书信英语-常用结束语 SQL中合并多行记录的方法总汇 C# 中的字符串函数及应用举例(转) 转:YetAnotherForum集成AD用户混合登录(一) AD验证类 - 沸石 - 博客园 英文函电书写基本原则 SQL Server 2005之PIVOT/UNPIVOT行列转换
ASHX 生成excel文件
沸石 · 2013-01-11 · via 博客园 - 沸石

private void GetCandidateExcelConverter(HttpContext context)
{
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;

// Workbook excelWorkbook = new Workbook();
string originalFile = context.Server.MapPath("~/webservice/report.xlsx");

Workbook excelWorkbook = new Workbook(originalFile);

filename = string.Format("report_{0}_{1:yyyyMMddHHmmss}.xls", context.Session["Name"], DateTime.Now);
LoadDataToCandidateExcel(context, excelWorkbook);

#region downlload excel
string exportFile = context.Server.MapPath("~/output/" + filename);
context.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
HttpContext.Current.Response.Expires = 1;
HttpContext.Current.Response.ExpiresAbsolute = System.DateTime.Now.AddMinutes(-1);
HttpContext.Current.Response.CacheControl = "Private";
HttpContext.Current.Response.AddHeader("pragma", "no-cache");
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
HttpContext.Current.Response.Charset = String.Empty;
byte[] fileData = excelWorkbook.SaveToStream().ToArray();
context.Response.OutputStream.Write(fileData, 0, fileData.Length);
context.Response.End();
System.IO.MemoryStream ms = new System.IO.MemoryStream(fileData);
Int64 dataToRead = fileData.Length;
int length = 0;
try
{
while (dataToRead > 0)
{
if (HttpContext.Current.Response.IsClientConnected)
{
byte[] buffer = new byte[10000];
length = ms.Read(buffer, 0, 10000);
HttpContext.Current.Response.OutputStream.Write(buffer, 0, length);
HttpContext.Current.Response.Flush();
dataToRead = dataToRead - length;
}
else
{
dataToRead = 1;
}
}
}
finally
{
if (ms == null)
ms.Close();
}
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
#endregion
}