2012-12-10 105 views
-2

如何使用C#中的itextSharp以不同數量的列創建PDF表。在PDF中創建不同大小和列的表

表1)

Column1  Column2  Column3  Column4  Column5  Column6 

表2)

Col1  Col2  Col3 

它必須看起來像

Column1  Column2  Column3  Column4  Column5  Column6 
Col1  Col2  Col3 
+3

顯示代碼,什麼ü試圖????? – sharad

回答

4

像這樣的事情?

Document doc  = new Document(PageSize.A4); 

    PdfPTable aTable    = new PdfPTable(6); 
    aTable.HorizontalAlignment  = Element.ALIGN_LEFT; 
    aTable.WidthPercentage   = 100; 
    aTable.AddCell("Column 1"); 
    aTable.AddCell("Column 2"); 
    aTable.AddCell("Column 3"); 
    aTable.AddCell("Column 4"); 
    aTable.AddCell("Column 5"); 
    aTable.AddCell("Column 6"); 

    doc.Add(aTable); 

    PdfPTable tp     = new PdfPTable(3); 
    tp.HorizontalAlignment   = Element.ALIGN_LEFT; 
    tp.WidthPercentage    = 50; 
    //tp.SetWidths(new []{60f, 20f, 20f}); 
    tp.AddCell("Col 1"); 
    tp.AddCell("Col 2"); 
    tp.AddCell("Col 3"); 

    doc.Add(tp); 
相關問題