2012-04-06 268 views
0

enter image description here我想在C#中使用iTextSharp庫創建表格。 我想要設置表格中單元格的寬度。設置PDF表格單元格寬度

我使用下面的代碼:

PdfPTable Ptbl_DetailsPerformance = new PdfPTable(7); 
Ptbl_DetailsPerformance.SetWidths(new int[7] { 20, 8, 8, 8, 8, 8, 1 }); 

PdfPCell cellValue = new PdfPCell(); 

現在我要動態設置單元格的寬度,但得到錯誤「寬度不能設置。」

我該怎麼辦?請幫助..

回答

0

那麼你不能在單元格級別設置widht,只能在表格中(如果我沒記錯的話,寬度在PdfPCell級別沒有setter)。

在您不瞭解您的問題的情況下很難幫助您。您可以在ITextSharp中使用colspan,或者在表級別計算您的「動態寬度」,但是...

您需要什麼?

編輯: iTextSharp的2.050727源(類Rectangle:PdfPCell從矩形區域中繼承,並沒有覆蓋寬)

public virtual float Width 
    { 
     get 
     { 
     return this.urx - this.llx; 
     } 
     set 
     { 
     throw new InvalidOperationException(MessageLocalization.GetComposedMessage("the.width.cannot.be.set")); 
     } 
    } 
+0

其實我有我在單槓顯示幾個值。所以,根據我想要設置單元格寬度的值,然後用顏色填充單元格。 – jitendra 2012-04-06 12:22:57

+0

而我不知道hwat是單槓......這是一張簡單的桌子嗎?一排,多排?任何打印屏幕,也許? – 2012-04-06 12:27:36

+0

我已添加圖片 – jitendra 2012-04-06 12:51:20