将asp.net导出为PDF时的PDF表结构

时间:2015-01-30 06:52:56

标签: c#

我有下面的代码来显示表格中的数据。我试图显示左,右,上,下边框的表格。在细胞内不应该有边界。以下代码显示左,右和上边框。如何显示底部边框?

PdfPTable table = new PdfPTable(5);
table.TotalWidth = 550f;
table.LockedWidth = true;
float[] widths = new float[] { 50f, 30f, 30f, 50f, 50f};
table.SetWidths(widths);
table.HorizontalAlignment = Element.ALIGN_CENTER;
addCell(table, "Product Name");
addCell(table, "System Type");
addCell(table, "Operation");
addCell(table, "Quality");
addCell(table, "Price");


addNewCell(table,"Mobile",1,0,0,0);
addNewCell(table, "A", 0, 0, 0, 0);
addNewCell(table, "O1", 0, 0, 0, 0);
addNewCell(table, "A1", 0, 0, 0, 0);
addNewCell(table, "100", 0, 1, 0, 0);

和addNewCell()和addCell()类似: -

private static void addCell(PdfPTable table, string text)
    {
         BaseFont bfTimes = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);
         iTextSharp.text.Font times = new iTextSharp.text.Font(bfTimes, 10, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK);
         PdfPCell cell = new PdfPCell(new Phrase(text, times));
         cell.Right = 0;
         cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
         cell.VerticalAlignment = PdfPCell.ALIGN_MIDDLE;
         Color myColor = WebColors.GetRGBColor("#F7FF00");
         cell.BackgroundColor = myColor;
         table.AddCell(cell);
    }
    private static void addNewCell(PdfPTable table, string text,int bordersizeleft,int borderright,int bordertop,int borderbottom)
    {
        BaseFont bfTimes = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);
        iTextSharp.text.Font times = new iTextSharp.text.Font(bfTimes, 12, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK);
        PdfPCell cell = new PdfPCell(new Phrase(text, times));
        cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
        cell.VerticalAlignment = PdfPCell.ALIGN_MIDDLE;
        //table.DefaultCell.Border = Rectangle.NO_BORDER;
        cell.BorderWidthLeft = bordersizeleft;
        cell.BorderWidthRight = borderright;
        cell.BorderWidthBottom = borderbottom;
        cell.BorderWidthTop = bordertop;
        table.AddCell(cell);

    }

请帮助我获得底部边框

enter image description here

1 个答案:

答案 0 :(得分:0)

使用

cell.DisableBorderSide()//Method

在addNewCell()中获取底部边框。