设置PDF表格单元格宽度

时间:2012-04-06 11:39:42

标签: c# itextsharp

enter image description here我正在尝试使用C#中的iTextSharp库创建一个表。 我想要设置表格中单元格的宽度。

我正在使用以下代码:

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

PdfPCell cellValue = new PdfPCell(); 

现在我想动态设置单元格的宽度,但会收到“无法设置宽度”的错误。

我该怎么办?请帮忙..

1 个答案:

答案 0 :(得分:0)

嗯,你不能在单元级别设置widht,只能在表格中设置(如果我记得很清楚,Width在PdfPCell级别没有setter)。

很难在不了解您的问题的情况下帮助您。您可以在ITextSharp中使用colspan,或者在表级别计算“动态宽度”,但是......

你需要什么?

编辑: itextsharp 2.050727 source(类Rectangle:PdfPCell继承自Rectangle,并不覆盖Width)

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