表格标题单元格有一个隔断线,其他标题不会改变它们的高度

问题描述

我向标题单元格添加一个大文本,表格的另一个单元格不会改变它们的高度 image

这是我的表的代码,我应该添加什么?

Table tblChcklist = new Table(UnitValue.CreatePercentArray(new float[] { 4,35,20,20 })).SetVerticalAlignment(VerticalAlignment.MIDDLE).SetHorizontalAlignment(iText.Layout.Properties.HorizontalAlignment.CENTER).UseAllAvailableWidth().SetFont(PdfFontFactory.CreateFont(StandardFonts.HELVETICA,PdfEncodings.WINANSI,false));
tblChcklist.SetKeepTogether(true).SetFontSize(10).SetFixedLayout();
tblChcklist.AddHeaderCell(handler.getCell(2,1,"No.",TextAlignment.CENTER).SetHorizontalAlignment(iText.Layout.Properties.HorizontalAlignment.CENTER).SetVerticalAlignment(VerticalAlignment.MIDDLE));
tblChcklist.AddHeaderCell(handler.getCell(2,$"Seccion {dtPreguntas.Rows[0]["nombreSeccion"] }",TextAlignment.LEFT).SetBold());
tblChcklist.AddHeaderCell(handler.getCell(0,"Si",TextAlignment.CENTER));
tblChcklist.AddHeaderCell(handler.getCell(0,"No","No Aplica",TextAlignment.CENTER));

这里是 handle.getCell 方法

public Cell getCell(int rowspan,int colspan,String text,TextAlignment alignment)
{
    Cell cell = new Cell(rowspan,colspan).Add(new Paragraph(text));
    cell.AddStyle(new Style().SetBorderBottom(new SolidBorder(ColorConstants.BLACK,0)));
    cell.AddStyle(new Style().SetBorderTop(new SolidBorder(ColorConstants.BLACK,0)));
    cell.SetPadding(0);
    cell.SetTextAlignment(alignment);
    cell.SetKeepTogether(true);
    return cell;
}

解决方法

如果我理解正确,您不会希望看到以下空格(以黄色突出显示):enter image description here

不过,这不是什么奇怪的空间,而是第二行尚未添加的单元格的位置。发生这种情况是因为您添加了第一个(“否”)和第二个(“Seccion...”)单元格,行跨度为 2,因此它们占用了两行的空间。但是,您仅通过添加 5 个单元格填充了第一行,因此第二行是空的,因此您会在那里看到一些空间。

所以这里有两种解决方案:要么添加更多单元格(如果您打算),要么不要将前两个单元格的行跨度值设置为 2。我相信后者应该是这种情况,因为,如果我得到关于您分享的片段的想法,这个大行跨度设置错误。