如何将DataTable和文本导出为PDF?

时间:2017-03-14 13:06:13

标签: asp.net vb.net

Dim dt As DataTable
dt=some query
Dim GridView1 As New GridView()
GridView1.AllowPaging = False
GridView1.AutoGenerateColumns = False
GridView1.DataSource = dt
GridView1.DataBind()
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=DataTable.pdf")
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Dim sw As New StringWriter()
Dim hw As New HtmlTextWriter(sw)
GridView1.RenderControl(hw)
Dim sr As New StringReader(sw.ToString())
Dim pdfDoc As New Document(PageSize.A4, 10.0F, 10.0F, 10.0F, 0.0F)
Dim htmlparser As New HTMLWorker(pdfDoc)
PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
pdfDoc.Open()
htmlparser.Parse(sr)
pdfDoc.Close()
Response.Write(pdfDoc)
Response.End()

我需要将文本和DataTable一起导出为PDF。我在GridView1.Columns.Count = 0之后得到DataBind()。在dt中有列,但在DataBind()之后,Columns.Count返回0。 dt = some query.but显示count = 0

0 个答案:

没有答案