0

我正在使用 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;
4

1 回答 1

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);
于 2013-07-11T19:08:47.200 回答