ASP.NET - 导出的GridView数据到Excel并直接发送邮件 [英] ASP.NET - Export gridview data to excel and directly send a mail

查看:220
本文介绍了ASP.NET - 导出的GridView数据到Excel并直接发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找一些示例编码才能够当一个页面被他推出自动当前gridview的数据导出到Excel文件,然后将其连接到邮件和发送邮件。

I'm looking some example coding to be able to whenever a page is launched he automatically exports the current gridview data to an excel-file and then attach it to a mail and send the mail.

我有一个导出到Excel的功能,但该功能让用户保存或查看该文件,我很喜欢,因为我希望我的脚本来自动运行跳过此步骤。

I have an export to excel function but this function asks the user to Save or View the file and I badly need to skip this step because I want my script to be running automatically.

如果有人可以帮助我,这将是AP preciated:)

If someone could help me with this this will be appreciated :)

谢谢
凯文

推荐答案

尝试用这个code

        string filename = "Test.xls"; 
        System.IO.StringWriter tw = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);

        //Get the H`enter code here`TML for the control.
        yourGrid.RenderControl(hw);
        //Write the HTML back to the browser.
        Response.ContentType = "application/vnd.ms-excel";
        Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename + "");

        Response.Write(tw.ToString());

这篇关于ASP.NET - 导出的GridView数据到Excel并直接发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆