问题
I started using iTextSharp to export my data from my grid to a PDF document.
As part of my grid I have columns which are not visible, however iTextSharp still export those columns which are invisible in the gridview to the PDF document.
How can I specify which columns on my GridView to export to the PDF document so that the columns which are "visible=false"
do not get displayed??
This is what I have so far:
protected void btnExport_Click(object sender, EventArgs e)
{
PdfPTable pdfTable = new PdfPTable(gvSchedule.HeaderRow.Cells.Count);
foreach (GridViewRow gridViewRow in gvSchedule.Rows)
{
foreach (TableCell tableCell in gridViewRow.Cells)
{
if (tableCell.Text == "CenterName")
{
continue;
}
PdfPCell pdfCell = new PdfPCell(new Phrase(tableCell.Text));
pdfTable.AddCell(pdfCell);
}
}
Document pdfDocument = new Document(PageSize.A4, 10f, 10f, 10f, 10f);
PdfWriter.GetInstance(pdfDocument, Response.OutputStream);
pdfDocument.Open();
pdfDocument.Add(pdfTable);
pdfDocument.Close();
Response.ContentType = "application/pdf";
Response.AppendHeader("content-disposition", "attachment;filename=mySchedule.pdf");
Response.Write(pdfDocument);
Response.Flush();
Response.End();
}
The two columns that I DO NOT want to display on my PDF document are:
<asp:BoundField DataField="Address" visible="false" HeaderText="Address" SortExpression="Address"/>
<asp:BoundField DataField="Area" visible="false" HeaderText="Area" SortExpression="Area"/>
Please advise on how I can export the data in my GridView to PDF using iTextSharp without the two columns mentioned above.
来源:https://stackoverflow.com/questions/48465254/specify-which-columns-to-export-to-pdf-from-gridview-using-itextsharp