【问题标题】:How to export GridView data to pdf file in Asp.net and C#?如何在 Asp.net 和 C# 中将 GridView 数据导出为 pdf 文件?
【发布时间】:2010-04-30 16:05:53
【问题描述】:

目前我面临着将完整的 GridView 数据导出到 pdf 文件以便用户保存的繁琐问题。我在 Asp.net 3.5 中使用 C# 作为语言。请指导我。

gridview 只包含文本值。

提前致谢。

【问题讨论】:

标签: c# .net asp.net gridview


【解决方案1】:
【解决方案2】:

nFOP + XSLT + XML = pdf |文档 | HTML

开源免费:)

K

【讨论】:

  • 感谢您的回答。请分享任何说明其将 gridview 数据导出为 pdf 的实现的链接。
  • nfop.sourceforge.net/article.html 应该让您了解如何使用它,您需要“Microsoft Visual J # NET Redistributable Package”来运行 nFOP。 K
【解决方案3】:
public override void VerifyRenderingInServerForm(Control control)
{
    /* Verifies that the control is rendered */
}

protected void GeneratePDF_Click(object sender, EventArgs e)
{
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", "attachment;filename=UserDetails.pdf");
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    GridView1.AllowPaging = false;
    GridView1.DataBind();
    GridView1.RenderControl(hw);
    GridView1.HeaderRow.Style.Add("width", "15%");
    GridView1.HeaderRow.Style.Add("font-size", "10px");
    GridView1.Style.Add("text-decoration", "none");
    GridView1.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
    GridView1.Style.Add("font-size", "8px");
    StringReader sr = new StringReader(sw.ToString());
    Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
    pdfDoc.Open();
    htmlparser.Parse(sr);
    pdfDoc.Close();
    Response.Write(pdfDoc);
    Response.End();   
}

【讨论】:

    猜你喜欢
    • 2012-06-30
    • 2017-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-04
    相关资源
    最近更新 更多