0

GridViewをPDFにエクスポートしてみました。エラーが発生します:

タイプ'iTextSharp.text.html.simpleparser.CellWrapper'のオブジェクトをタイプ'iTextSharp.text.Paragraph'にキャストできません。

ここでエラーがスローされます

htmlparser.Parse(sr);
4

1 に答える 1

0

データバインディングと解析の前に、並べ替えとページングを無効にする必要があります。

コードは次のとおりです。

Response.ContentType = "application/pdf";

Response.AddHeader("content-disposition","attachment;filename=GridViewExport.pdf");

Response.Cache.SetCacheability(HttpCacheability.NoCache);

StringWriter sw = new StringWriter();

HtmlTextWriter hw = new HtmlTextWriter(sw);

GridView1.AllowPaging = false;     <----

GridView1.AllowSorting = false;    <----

GridView1.DataBind();

GridView1.RenderControl(hw);

StringReader sr = new StringReader(sw.ToString());

Document pdfDoc = new Document(PageSize.A4, 10f,10f,10f,0f);

HTMLWorker htmlparser = new HTMLWorker(pdfDoc);

PdfWriter.GetInstance(pdfDoc, Response.OutputStream);

pdfDoc.Open();

htmlparser.Parse(sr);

pdfDoc.Close();

Response.Write(pdfDoc);

Response.End(); 
于 2013-03-28T18:26:49.530 に答える