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

推荐订阅源

J
Java Code Geeks
Last Week in AI
Last Week in AI
T
Tailwind CSS Blog
WordPress大学
WordPress大学
B
Blog RSS Feed
T
The Blog of Author Tim Ferriss
F
Fortinet All Blogs
aimingoo的专栏
aimingoo的专栏
MongoDB | Blog
MongoDB | Blog
博客园 - Franky
C
Check Point Blog
P
Proofpoint News Feed
H
Help Net Security
月光博客
月光博客
博客园_首页
Stack Overflow Blog
Stack Overflow Blog
博客园 - 三生石上(FineUI控件)
Martin Fowler
Martin Fowler
Recent Announcements
Recent Announcements
人人都是产品经理
人人都是产品经理
U
Unit 42
美团技术团队
I
InfoQ
A
About on SuperTechFans

博客园 - 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();