水晶报表使用按钮导出EXCEL

这篇博客介绍了如何在C#中使用水晶报表组件导出报表为Excel文件。通过`ExportToExcel`方法,设置导出选项,然后利用HttpResponse对象响应导出的Excel文件,实现点击按钮直接下载。同时,博客提供了多个有用的资源链接,帮助读者深入理解和实践。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

    public bool ExportToExcel(string ExcelFileName)
    {
        try
        {
            FileOPS.DiskFileName = ExcelFileName;

            ExportOptions ExOPS = myReport.ExportOptions;//cr.ExportOptions;
            ExOPS.ExportDestinationOptions = FileOPS;
            ExOPS.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
            ExOPS.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.ExcelRecord;
            myReport.Export();//myReport.Export(ExOPS);

            System.Web.HttpResponse Response = System.Web.HttpContext.Current.Response;
            Response.ClearContent();
            Response.ClearHeaders();

            Response.ContentType = "application/vnd.ms-excel";
            Response.AddHeader("Content-Disposition", "attachment;filename=" + ExcelFileName);//下载时要保存的默认文件名

            Response.WriteFile(ExcelFileName);
            Response.Flush();
            Response.Close();

            return true;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
           // 创建Excel文件以及路径
            string map = Server.MapPath(@"../ExcelReport");
            string url = map + "/MonthReport{0:yyyyMMddHHmmss}.xls";
            string ExcelFileName = string.Format(url, DateTime.Now);  //字符格式化

            bool msg = ExportToExcel(ExcelFileName);  //将水晶报表的信息保存到指定文件里

            if (msg == true)
            {
                string URL = "DownLoad.aspx?Path=" + url;
                Server.Transfer(URL);
            }

        }
        catch (Exception ex)
        {
           // ShowMessage(ex.Message);
        }
    }

 

 

有用的EXCEL链接
http://topic.youkuaiyun.com/u/20100428/16/72028ea4-fbab-49f3-b392-12d7524df9d5.html

http://topic.youkuaiyun.com/u/20090707/16/0618de94-4c4b-4186-8d48-f4a8f53117ae.html(完美Excel)


http://www.cnblogs.com/peaceli/archive/2008/04/13/1151520.html

 


http://topic.youkuaiyun.com/u/20081110/17/5d552cfd-9468-49bb-8767-c6ae80b117b3.html

http://topic.youkuaiyun.com/u/20081110/17/5d552cfd-9468-49bb-8767-c6ae80b117b3.html

 

水晶报表导出Excel:
http://qianshao.blog.51cto.com/935360/203640

水晶报表导出Excel/Word/Pdf:
http://cache.baidu.com/c?m=9d78d513d9d430df4f9ee3697d61c0151c4381132ba7d3020cde843890732c37506692ef7c7c47599184682041f14606acb6746536703daade8dcd5dddccc3747fd67a61310b8636438e46b2b51d5d867c925aecb24aa7ebaa69d7f9cfd3dd5656d751026780f1965f0710cf65fa033194fcdf174b&p=882a944292904ea802f6c3665648&user=baidu&fm=sc&query=%CB%AE%BE%A7%B1%A8%B1%ED+FileOPS&qid=95f784e812fd17f2&p1=1

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值