iTextSharp 添加表格

添加表格

设置表格列的数量

 PdfPTable pdfPTable = new PdfPTable(4);//4 列

设置表格宽度

pdfPTable.TotalWidth = doc.PageSize.Width - 72;
pdfPTable.LockedWidth = true;//锁定宽度

添加单元格

设置单元格内容的对齐方式

//水平居中
pdfPTable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;

添加单元格和单元格内容

PdfPCell cell = new PdfPCell(new Phrase("1"));
pdfPTable.AddCell(cell);
pdfPTable.AddCell("2");
pdfPTable.AddCell("3");
pdfPTable.AddCell("4");

注意:添加的单元格要和表格列数对应

猜你喜欢

转载自blog.csdn.net/weixin_43796392/article/details/124371242