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

推荐订阅源

Martin Fowler
Martin Fowler
有赞技术团队
有赞技术团队
博客园_首页
H
Help Net Security
GbyAI
GbyAI
aimingoo的专栏
aimingoo的专栏
V
Visual Studio Blog
The Cloudflare Blog
腾讯CDC
Jina AI
Jina AI
Last Week in AI
Last Week in AI
月光博客
月光博客
博客园 - 叶小钗
Google DeepMind News
Google DeepMind News
B
Blog RSS Feed
Blog — PlanetScale
Blog — PlanetScale
人人都是产品经理
人人都是产品经理
Engineering at Meta
Engineering at Meta
Y
Y Combinator Blog
Hugging Face - Blog
Hugging Face - Blog
博客园 - 聂微东
爱范儿
爱范儿
N
Netflix TechBlog - Medium
F
Fortinet All Blogs

博客园 - pysharp

openstack horizon api step by step understanding horizon's template path what can PsTools\psexec do! - pysharp What's New in Python3.0 - pysharp [转]利用adsutil.vbs脚本创建自定义web站点 我的2008. sql基础篇,不断更新中...... TypeConvert Demo javascript 调试器v1.0.0.0 Dundas Chart Demo For New User - pysharp c#面向对象中的继承初步认识 .net 集合类初步认识 c# 目录操作类 c# 文件操作类 - pysharp - 博客园 关于urlrewrite的小DEMO - pysharp - 博客园 c# 动态编译方法 c# 读取Excel到datable 排序算法 c#实现 简单使用nHibernate,新手练习用。
asp.net 下载和在线预览Excel的方法
pysharp · 2008-01-24 · via 博客园 - pysharp

直接代码,红色字体是对大家有用地。

public string ExcelCache
        {
            get
            {
                string _path = Path.Combine(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath, "ExcelBuffer\\");
                if (!Directory.Exists(_path))
                {
                    Directory.CreateDirectory(_path);
                }
                return _path;
            }

        }

                Report rpt = Report.LoadReport(Convert.ToInt32(reportID));
                ExcelHeaderBuilder builder = new ExcelHeaderBuilder();
                ExcelWorkbook book = new ExcelWorkbook();
                book.CreateSheet(sheetName);
                book.SetActiveSheet = sheetName;
                ExcelWorksheet sheet = book.GetSheet(sheetName);
                ExcelCellStyle style = book.CreateStyle();
                style.BorderColour = EnumColours.Black;
                style.BorderLineStyle = EnumLineStyle.Thin;
                style.Font.Name = "黑体";
                style.Font.Size = 12;
                style.HorizontalAlignment = EnumHorizontalAlignment.Center;
                style.VerticalAlignment = EnumVerticalAlignment.Center;

                builder.Style = style;
                builder.MakeHeader(sheet, rpt);book.Save(path);
                    //下载
                    HttpContext.Current.Response.Clear();
                    HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + Path.GetFileName(path));
                    HttpContext.Current.Response.ContentType = "application/octet-stream";
                    HttpContext.Current.Response.Charset = "GB2312";
                    HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
                    HttpContext.Current.Response.WriteFile(path);
                    HttpContext.Current.Response.Flush();
            
                    //在线
                    HttpContext.Current.Response.Clear();
                    HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=" + Path.GetFileName(path));
                    HttpContext.Current.Response.ContentType = "application/octet-stream";
                    HttpContext.Current.Response.Charset = "GB2312";
                    HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
                    HttpContext.Current.Response.WriteFile(path);
                    HttpContext.Current.Response.Flush();