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

Chunks の使用について

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 に答える
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 に答える