2013-07-11 3 views
0

я использую iTextSharp для создания таблицы, и я хочу сделать Generic из Pdfcells вместо добавления вручную, как я могу использовать общий для PdfPcells

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

Is [PdfPTable.getDefaultCell()] (http://api.itextpdf.com/itext/com/itextpdf/text/pdf/PdfPTable.html#getDefaultCell%28%29) то, что вы ищете ? –

ответ

1

Если комментарий @Alexis Птичьем не то, что вы ищите, как насчет функции-обертки?

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); 
+0

большое спасибо, моя идея собирается передать параметр методу, который делает цикл и генерирует объект, если получил мою идею, но действительно полезный метод :) – Sonic

Смежные вопросы