0

我想使用列表在 cell3 中添加值:lstMMVat15SaleDetail

 PdfPTable myTable = new PdfPTable(3);
 myTable.DefaultCell.Padding = 1;`
 myTable.DefaultCell.BorderColor = new Color(123, 123, 163);   
 myTable.DefaultCell.Padding = 1;
 myTable.SetWidths(new int[] { 10, 60, 30 });
 myTable.TotalWidth = 100;`

    PdfPCell header1 = new PdfPCell(new Phrase("1."));
    PdfPCell header2 = new PdfPCell(new Phrase("SALE DETAILS"));
    PdfPCell header3 = new PdfPCell(new Phrase("AMOUNT"));
    header1.BackgroundColor = iTextSharp.text.Color.GRAY;
    header2.BackgroundColor = iTextSharp.text.Color.GRAY;
    header3.BackgroundColor = iTextSharp.text.Color.GRAY;
    myTable.AddCell(header1);
    myTable.AddCell(header2);
    myTable.AddCell(header3);

    for (int i = 0; i < lstMMVat15SaleDetail.Count; i++)
    {
        PdfPCell cell1 = new PdfPCell(new Phrase(lstMMVat15SaleDetail[i].SlNo));
        PdfPCell cell2 = new PdfPCell(new Phrase(lstMMVat15SaleDetail[i].Name));
        PdfPCell cell3 = new PdfPCell(new Phrase());
        myTable.AddCell(cell1);
        myTable.AddCell(cell2);
        myTable.AddCell(cell3);
    }
    for (int i = 0; i < lstMMVat15SaleDetail.Count; i++)
    {
        PdfPCell cell3 = new PdfPCell(new Phrase());
        cell3.Phrase = new Phrase(lstMainVat15Detail[0].SalesA.ToString());
        cell3.Phrase = new Phrase(lstMainVat15Detail[0].SalesB.ToString());
        cell3.Phrase = new Phrase(lstMainVat15Detail[0].SalesC.ToString());
        cell3.Phrase = new Phrase(lstMainVat15Detail[0].SalesD.ToString());
        cell3.Phrase = new Phrase(lstMainVat15Detail[0].SalesE.ToString());
        cell3.Phrase = new Phrase(lstMainVat15Detail[0].SalesF.ToString());
        cell3.Phrase = new Phrase(lstMainVat15Detail[0].SalesG.ToString());
        cell3.Phrase = new Phrase(lstMainVat15Detail[0].SalesH.ToString());
        myTable.AddCell(cell3);
    }
 pdfDoc.Add(myTable);
4

2 回答 2

0
PdfPTable myTable = new PdfPTable(3);
myTable.DefaultCell.Padding = 1;
myTable.DefaultCell.BorderColor = new Color(123, 123, 163);   
myTable.DefaultCell.Padding = 1;
myTable.SetWidths(new int[] { 10, 60, 30 });
myTable.TotalWidth = 100;

PdfPCell header1 = new PdfPCell(new Phrase("1."));
PdfPCell header2 = new PdfPCell(new Phrase("SALE DETAILS"));
PdfPCell header3 = new PdfPCell(new Phrase("AMOUNT"));
header1.BackgroundColor = iTextSharp.text.Color.GRAY;
header2.BackgroundColor = iTextSharp.text.Color.GRAY;
header3.BackgroundColor = iTextSharp.text.Color.GRAY;
myTable.AddCell(header1);
myTable.AddCell(header2);
myTable.AddCell(header3);

for (int i = 0; i < lstMMVat15SaleDetail.Count; i++)
{
    PdfPCell cell1 = new PdfPCell(new Phrase(lstMMVat15SaleDetail[i].SlNo));
    // or:   
    // PdfPCell cell1 = new PdfPCell(new Phrase((i + 1).ToString() + "."));
    PdfPCell cell2 = new PdfPCell(new Phrase(lstMMVat15SaleDetail[i].Name));
    PdfPCell cell3 = new PdfPCell(new Phrase(lstMainVat15Detail[0][i].ToString()));
    myTable.AddCell(cell1);
    myTable.AddCell(cell2);
    myTable.AddCell(cell3);
}
pdfDoc.Add(myTable);
于 2012-07-13T10:59:58.997 回答
0

如何使用块

for (int i = 0; i < lstMMVat15SaleDetail.Count; i++) 
{ 
    PdfPCell cell1 = new PdfPCell(new Phrase(lstMMVat15SaleDetail[i].SlNo)); 
    PdfPCell cell2 = new PdfPCell(new Phrase(lstMMVat15SaleDetail[i].Name)); 
    PdfPCell cell3 = new PdfPCell(new Phrase()); 

    cell3.Phrase.Add(new Chunk(lstMainVat15Detail[0].SalesA.ToString())); 
    cell3.Phrase.Add(new Chunk(lstMainVat15Detail[0].SalesB.ToString())); 
    cell3.Phrase.Add(new Chunk(lstMainVat15Detail[0].SalesC.ToString())); 
    cell3.Phrase.Add(new Chunk(lstMainVat15Detail[0].SalesD.ToString())); 
    cell3.Phrase.Add(new Chunk(lstMainVat15Detail[0].SalesE.ToString())); 
    cell3.Phrase.Add(new Chunk(lstMainVat15Detail[0].SalesF.ToString())); 
    cell3.Phrase.Add(new Chunk(lstMainVat15Detail[0].SalesG.ToString())); 
    cell3.Phrase.Add(new Chunk(lstMainVat15Detail[0].SalesH.ToString()));


    myTable.AddCell(cell1); 
    myTable.AddCell(cell2); 
    myTable.AddCell(cell3); 
} 
于 2012-07-13T11:01:46.130 回答