我正在使用iTextSharp生成表格,我想制作一个通用的Pdfcells而不是手动添加
PdfPCell HeadCell0 = new PdfPCell(new Paragraph("FullName", Htitle));
HeadCell0.BackgroundColor = Color.LIGHT_GRAY;
PdfPCell HeadCell1 = new PdfPCell(new Paragraph("Username", Htitle));
HeadCell1.BackgroundColor = Color.LIGHT_GRAY;
PdfPCell HeadCell2 = new PdfPCell(new Paragraph("Email", Htitle));
HeadCell2.BackgroundColor = Color.LIGHT_GRAY;
PdfPCell HeadCell3 = new PdfPCell(new Paragraph("Department", Htitle));
HeadCell3.BackgroundColor = Color.LIGHT_GRAY;
PdfPCell HeadCell4 = new PdfPCell(new Paragraph("AddedBy", Htitle));
HeadCell4.BackgroundColor = Color.LIGHT_GRAY;
PdfPCell HeadCell5 = new PdfPCell(new Paragraph("Account Type", Htitle));
HeadCell5.BackgroundColor = Color.LIGHT_GRAY;
答案 0 :(得分:1)
如果@Alexis Pigeon的评论不是你想要的,那么包装函数怎么样?
public static PdfPCell MakeHeader(string text, iTextSharp.text.Font Htitle) {
PdfPCell HeadCell = new PdfPCell(new Paragraph(text, Htitle));
HeadCell.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY;
return HeadCell;
}
PdfPCell HeadCell0 = MakeHeader("FullName", Htitle);