itextSharp 空值显示  
itextSharp null value showing  
我正在使用 iTextSharp 从 gridview 创建 pdf。当 table 中有空值时,pdf 会在其位置放置一个  。如何删除它并显示空值?我知道 pdf 是在 gridview 已经填充之后创建的,但是有没有办法告诉它 null 应该显示为空白?我的代码如下:
Protected Sub btnPDF_Click(sender As Object, e As System.EventArgs) Handles btnPDF.Click
Dim pdfTable As New PdfPTable(grdResults.HeaderRow.Cells.Count)
For Each headerCell As TableCell In grdResults.HeaderRow.Cells
Dim font As New Font()
font.Color = New BaseColor(grdResults.HeaderStyle.ForeColor)
Dim pdfCell As New PdfPCell(New Phrase(headerCell.Text, font))
pdfCell.BackgroundColor = New BaseColor(grdResults.HeaderStyle.BackColor)
pdfTable.AddCell(pdfCell)
Next
For Each gridViewRow As GridViewRow In grdResults.Rows
For Each tableCell As TableCell In gridViewRow.Cells
Dim font As New Font()
font.Color = New BaseColor(grdResults.RowStyle.ForeColor)
Dim pdfCell As New PdfPCell(New Phrase(tableCell.Text, font))
pdfCell.BackgroundColor = New BaseColor(grdResults.RowStyle.BackColor)
pdfTable.AddCell(pdfCell)
Next
Next
Dim pdfDocument As New Document(iTextSharp.text.PageSize.A4, 10.0F, 10.0F, 10.0F, 10.0F)
pdfDocument.SetPageSize(PageSize.A4.Rotate())
PdfWriter.GetInstance(pdfDocument, Response.OutputStream)
pdfDocument.Open()
pdfDocument.Add(pdfTable)
pdfDocument.Close()
Response.ContentType = "application/pdf"
Response.AppendHeader("content-disposition", "attachment, filename-results.pdf")
Response.Write(PdfDocument)
Response.Flush()
Response.End()
End Sub
我在 pdf 中收到的值来自计算字段。当没有计算值时,它不会在 gridview 单元格中放置任何内容,因此它会在 pdf 中放置空白 space 值。我回到计算,如果一个值没有确定,我会为该值放置一个 space。例如-
If dtRaw.Rows(0).Item("ParameterName").ToString() <> "NOY" Then
drCalcRow("NAAQGreater") = iNAAQS
drCalcRow("NAAQGreater80") = iNAAQS80
Else
drCalcRow("NAAQGreater") = " "
drCalcRow("NAAQGreater80") = " "
End If
它可以工作,但是它为代码增加了很多。最好有一次可以检查它在写入 pdf 时何时循环遍历行。我尝试了几件事,但没有任何效果,甚至没有产生影响。
我正在使用 iTextSharp 从 gridview 创建 pdf。当 table 中有空值时,pdf 会在其位置放置一个  。如何删除它并显示空值?我知道 pdf 是在 gridview 已经填充之后创建的,但是有没有办法告诉它 null 应该显示为空白?我的代码如下:
Protected Sub btnPDF_Click(sender As Object, e As System.EventArgs) Handles btnPDF.Click
Dim pdfTable As New PdfPTable(grdResults.HeaderRow.Cells.Count)
For Each headerCell As TableCell In grdResults.HeaderRow.Cells
Dim font As New Font()
font.Color = New BaseColor(grdResults.HeaderStyle.ForeColor)
Dim pdfCell As New PdfPCell(New Phrase(headerCell.Text, font))
pdfCell.BackgroundColor = New BaseColor(grdResults.HeaderStyle.BackColor)
pdfTable.AddCell(pdfCell)
Next
For Each gridViewRow As GridViewRow In grdResults.Rows
For Each tableCell As TableCell In gridViewRow.Cells
Dim font As New Font()
font.Color = New BaseColor(grdResults.RowStyle.ForeColor)
Dim pdfCell As New PdfPCell(New Phrase(tableCell.Text, font))
pdfCell.BackgroundColor = New BaseColor(grdResults.RowStyle.BackColor)
pdfTable.AddCell(pdfCell)
Next
Next
Dim pdfDocument As New Document(iTextSharp.text.PageSize.A4, 10.0F, 10.0F, 10.0F, 10.0F)
pdfDocument.SetPageSize(PageSize.A4.Rotate())
PdfWriter.GetInstance(pdfDocument, Response.OutputStream)
pdfDocument.Open()
pdfDocument.Add(pdfTable)
pdfDocument.Close()
Response.ContentType = "application/pdf"
Response.AppendHeader("content-disposition", "attachment, filename-results.pdf")
Response.Write(PdfDocument)
Response.Flush()
Response.End()
End Sub
我在 pdf 中收到的值来自计算字段。当没有计算值时,它不会在 gridview 单元格中放置任何内容,因此它会在 pdf 中放置空白 space 值。我回到计算,如果一个值没有确定,我会为该值放置一个 space。例如-
If dtRaw.Rows(0).Item("ParameterName").ToString() <> "NOY" Then
drCalcRow("NAAQGreater") = iNAAQS
drCalcRow("NAAQGreater80") = iNAAQS80
Else
drCalcRow("NAAQGreater") = " "
drCalcRow("NAAQGreater80") = " "
End If
它可以工作,但是它为代码增加了很多。最好有一次可以检查它在写入 pdf 时何时循环遍历行。我尝试了几件事,但没有任何效果,甚至没有产生影响。