将gridview导出为pdf时出现问题 [英] Problem in exporting gridview to pdf
问题描述
大家好
我在将gridview导出为pdf时遇到问题。
问题是保存在pdf文件中的数据没有gridview或列名称的标题
这里是我的代码:
Response.ContentType = application / pdf
Response.AddHeader( content-disposition, attachment; filename = GridViewExport.pdf)
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Dim sw 作为 新 StringWriter()
Dim hw 作为 新 HtmlTextWriter(sw)
gv_reports.AllowPaging = False
gv_reports.DataBind()
gv_reports.RenderControl(hw)
Dim sr As 新 StringReader(sw.ToString())
Dim pdfDoc 作为 新文档(PageSize.A4, 10 .0F, 10 .0F, 10 .0F, 0 .0F)
Dim htmlparser As < span class =code-keyword>新 HTMLWorker(pdfDoc)
PdfWriter.GetInstance(pdfDoc,Response.OutputStream)
pdfDoc.Open()
htmlparser.Parse(sr) )
pdfDoc.Close()
Response.Write(pdfDoc)
响应。结束()
如果为gridview添加样式:
gv_reports.H eaderRow.Style.Add( width, 15%)
gv_reports.HeaderRow.Style.Add( font-size, 9px)
gv_reports.Style.Add( text-decoration, none)
gv_reports.Style.Add( font-family, Arial,Helvetica,sans- serif;)
gv_reports.Style.Add( font-size, 8px)
相同的错误foreach行:
对象引用未设置为对象的实例。
这些库:
进口系统
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml.Serialization
Imports System.Xml
Imports System.Data
Imports iTextSharp.text.pdf
Imports iTextSharp.text.html
Imports System.IO
Imports System.Collections
Imports iTextSharp.text
Imports iTextSharp.text .html.simpleparser
Imports System.Net
我不想为gridview添加样式只是gridview样式我在HTML页面中指定了它们,就像我导出的单词一样,我会得到相同的样式
谢谢
up up up up up up up up up up up up up up up up up up up up up up up up up up up up up up up >Hi everyone
I am facing problem in exporting gridview to pdf.
The problem is data saved in pdf file without the header of gridview or columns names
here is my code:
Response.ContentType = "application/pdf" Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf") Response.Cache.SetCacheability(HttpCacheability.NoCache) Dim sw As New StringWriter() Dim hw As New HtmlTextWriter(sw) gv_reports.AllowPaging = False gv_reports.DataBind() gv_reports.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()
If add style to gridview:
gv_reports.HeaderRow.Style.Add("width", "15%") gv_reports.HeaderRow.Style.Add("font-size", "9px") gv_reports.Style.Add("text-decoration", "none") gv_reports.Style.Add("font-family", "Arial, Helvetica, sans-serif;") gv_reports.Style.Add("font-size", "8px")
The same error foreach line:
Object reference not set to an instance of an object.
And these the libraries:
Imports System Imports System.Web.Services Imports System.Web.Services.Protocols Imports System.Xml.Serialization Imports System.Xml Imports System.Data Imports iTextSharp.text.pdf Imports iTextSharp.text.html Imports System.IO Imports System.Collections Imports iTextSharp.text Imports iTextSharp.text.html.simpleparser Imports System.Net
I do not want to add style for gridview just gridview style that I specified them in HTML page like when I export as word the same style I will get
Thank you解决方案up up up up up up up up up up up up up up up up up up up up up up up up up up up
这篇关于将gridview导出为pdf时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!