GridView数据下载到Excel和Pdf文件中 [英] GridView Data downlod into Excel and Pdf file

查看:199
本文介绍了GridView数据下载到Excel和Pdf文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



我在gridview控件中有一些数据现在我想下载为Excel文件和.pdf格式如何转换和下载?

Hi Friends,

I have some data in gridview controls now I want to download as a Excel file and .pdf formats how can I convert and download it?

推荐答案

请看看这篇文章:将数据导出到Excel,Word,PDF,无需Dat​​aBase自动化



介绍如何创建向导以将数据导出为Excel,PDF和其他文档格式。并且数据将首先导出到DataGridView,然后从此DataGridView导出到Excel,PDF。
Pleas have a look at this article: Export Data to Excel, Word, PDF without Automation from DataBase.

It introduces how to create a wizard to export data to Excel, PDF and other document formats. And the data will be exported to DataGridView firstly and then export to Excel, PDF from this DataGridView.


对于PDF:

HTML使用itextsharp转换为PDF [ ^ ]



对于Excel:

For PDF:
HTML convert to PDF using itextsharp[^]

For Excel:
protected void btnExpExcel_Click(object sender, EventArgs e)
        {
            Response.ClearContent();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Report.xls"));
            Response.ContentType = "application/ms-excel";
 
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
 
            DataTable dt = new DataTable();
            dt = (DataTable)Session["dtReport"];
 
            gvMISReport.AllowPaging = false;
 
            gvMISReport.DataSource = dt;
            gvMISReport.DataBind();
 
            //Change the Header Row back to white color
            gvMISReport.HeaderRow.Style.Add("background-color", "#FFFFFF");
            
            //Applying stlye to gridview header cells
            for (int i = 0; i < gvMISReport.HeaderRow.Cells.Count; i++)
            {
                gvMISReport.HeaderRow.Cells[i].Style.Add("background-color", "#157CB0");
            }
            int j = 1;
            
            //This loop is used to apply stlye to cells based on particular row
            foreach (GridViewRow gvrow in gvMISReport.Rows)
            {
                gvrow.BackColor = Color.White;
                if (j <= gvMISReport.Rows.Count)
                {
                    if (j % 2 != 0)
                    {
                        for (int k = 0; k < gvrow.Cells.Count; k++)
                        {
                            gvrow.Cells[k].Style.Add("background-color", "#EFF3FB");
                        }
                    }
                }
                j++;
            }
            gvMISReport.RenderControl(htw);
            Response.Write(sw.ToString());
            Response.End();
        }


检查以下链接:

将GridView导出到Pdf-ASP.NET [ ^ ]

了解如何使用iTextSharp.dll将gridview导出为pdf文件 [ ^ ]

如何以Excel格式下载GridView数据 [ ^ ]

如何使用C#将GridView数据转换为Excel,PDF,Word文件 [ ^ ]





--Amit
Check the links below:
Export GridView To Pdf-ASP.NET[^]
Learn how to export gridview to a pdf file using iTextSharp.dll[^]
How to download GridView data as Excel[^]
How to convert GridView data to Excel, PDF, Word file using C#[^]


--Amit


这篇关于GridView数据下载到Excel和Pdf文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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