c# – 如何使用itext sharp设置pdf中表格的垂直线?
我有一张垂直和水平线条的桌子.但我不想要水平线.我只想要垂直线.我怎么设置它.我预期的o / p是
我的表格代码 PdfPTable table = new PdfPTable(5); table.TotalWidth = 510f;//table size table.LockedWidth = true; table.HorizontalAlignment = 0; table.SpacingBefore = 10f;//both are used to mention the space from heading table.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT; table.AddCell(new Phrase(new Phrase(" SL.NO",font1))); table.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT; table.AddCell(new Phrase(new Phrase(" SUBJECTS",font1))); table.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT; table.AddCell(new Phrase(new Phrase(" MARKS",font1))); table.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT; table.AddCell(new Phrase(new Phrase(" MAX MARK",font1))); table.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT; table.AddCell(new Phrase(new Phrase(" CLASS AVG",font1))); Doc.Add(table); 例如: 有人请帮忙 解决方法
您可以更改单元格的边框,使它们只显示垂直线条.如何执行此操作取决于您将单元格添加到表中的方式.
这是两种方法: 1.您显式创建PdfPCell对象: PdfPCell cell = new PdfPCell(); 在这种情况下,仅显示单元格的左边框.对于行中的最后一个单元格,您还应该添加右边框: cell.Border = PdfPCell.LEFT | PdfPCell.RIGHT; 2.隐式创建PdfPCell对象: 在这种情况下,您不要自己创建PdfPCell对象,而是让iTextSharp创建单元格.这些单元格将复制在PdfPTable级别定义的DefaultCell的属性,因此您需要更改此: table.DefaultCell.Border = Rectangle.LEFT | Rectangle.RIGHT; table.addCell("cell 1"); table.addCell("cell 2"); table.addCell("cell 3"); 现在所有单元格都没有顶部或底部边框,只有左边框和右边框.你会画出一些额外的线条,但没有人注意到线条重合. 另见Hiding table border in iTextSharp 例如: PdfPTable table = new PdfPTable(5); table.TotalWidth = 510f;//table size table.LockedWidth = true; table.SpacingBefore = 10f;//both are used to mention the space from heading table.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT; table.DefaultCell.Border = PdfPCell.LEFT | PdfPCell.RIGHT; table.AddCell(new Phrase(" SL.NO",font1)); table.AddCell(new Phrase(" SUBJECTS",font1)); table.AddCell(new Phrase(" MARKS",font1)); table.AddCell(new Phrase(" MAX MARK",font1)); table.AddCell(new Phrase(" CLASS AVG",font1)); Doc.Add(table); 无需多次定义DefaultCell的属性.没有必要像这样嵌套Phrase构造函数:new Phrase(new Phrase(“content”)). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |