【发布时间】:2018-08-21 11:51:52
【问题描述】:
我有一张桌子,一切正常,但只有一个问题。 即使我设置了正确的列,它也只是打印出每列的默认宽度......
在这种情况下,我尝试设置一个 float[](在实例化表格时)以查看是否可以设置每列的宽度(即使 Cell 对象的 colspan 应该已经处理了它),但是即便如此,它也没有改变。以前,我有列数的整数,但结果是一样的。我需要对此进行一些澄清,因为部分文档已过时。
doc.Add(NewTable(new float[4] { 0, 0, 0, 0 }, new float[3] { 1, 5, 5 }, 250, 0, -1, 200, 150,
new List<Cell>() {
NewCell(new Paragraph("N.º do Auto:").SetFont(FontBold), ColorGray, new SolidBorder(1),1, 1, 2.5f, HorizontalAlignment.LEFT,VerticalAlignment.MIDDLE),
NewCell(new Paragraph("fdgdfgdfg").SetFont(FontRegular), ColorGray, new SolidBorder(1),1, 2, 2.5f, HorizontalAlignment.LEFT,VerticalAlignment.MIDDLE),
NewCell(new Paragraph("Data:").SetFont(FontBold), ColorGray, Border.NO_BORDER,1, 1, 2.5f, HorizontalAlignment.LEFT,VerticalAlignment.MIDDLE),
NewCell(new Paragraph(DateTime.Now.ToString("dd/MM/yyyy")).SetFont(FontRegular), ColorGray, Border.NO_BORDER,1, 2, 2.5f, HorizontalAlignment.LEFT,VerticalAlignment.MIDDLE),
NewCell(new Paragraph("Morada:").SetFont(FontBold), ColorGray, Border.NO_BORDER,1, 1, 2.5f, HorizontalAlignment.LEFT,VerticalAlignment.MIDDLE),
NewCell(new Paragraph("fdgdfgdfg").SetFont(FontRegular), ColorGray, Border.NO_BORDER,1, 2, 2.5f, HorizontalAlignment.LEFT,VerticalAlignment.MIDDLE)
}));
/// <summary>
/// Creates a new table
/// </summary>
/// <param name="paddings">An array of values to set the table's paddings (top, right, bottom, left).</param>
/// <param name="pointColumnWidths">An array of values to specify the number of columns ocupied by each cell in the row.</param>
/// <param name="width">The table's width.</param>
/// <param name="rowStart">The table row from which to start writing.</param>
/// <param name="rowEnd">The table row to which to end writing (-1 for all rows).</param>
/// <param name="horizontalPosition">The table's horizontal position (from the bottom left).</param>
/// <param name="verticalPosition">The table's vertical position (from the bottom left).</param>
/// <param name="cells">A list of cells to be added to the table.</param>
/// <returns></returns>
private static Table NewTable(float[] paddings, float[] pointColumnWidths, float width, int rowStart, int rowEnd, float horizontalPosition, float verticalPosition, List<Cell> cells)
{
Table table = new Table(pointColumnWidths);
table.SetPaddings(paddings[0], paddings[1], paddings[2], paddings[3]);
foreach (Cell cell in cells)
table.AddCell(cell);
table.SetFixedPosition(horizontalPosition, verticalPosition, width);
return table;
}
/// <summary>
/// Creates a new cell
/// </summary>
/// <param name="paragraph">A Paragraph object with the content.</param>
/// <param name="backgroundColor">The background color of the cell.</param>
/// <param name="border">The border to be applied to the cell.</param>
/// <param name="rowSpan">The number of rows that the cell will ocupy in the table.</param>
/// <param name="colSpan">The number of columns that the cell will ocupy in the table.</param>
/// <param name="padding">The padding of the cell.</param>
/// <param name="horizontalAlignment">The enum value for the horizontal alignment. Ex: HorizontalAlignment.LEFT</param>
/// <param name="verticalAlignment">The enum value for the vertical alignment. Ex: VerticalAlignment.MIDDLE</param>
/// <returns></returns>
private static Cell NewCell(Paragraph paragraph, Color backgroundColor, Border border, int rowSpan, int colSpan, float padding, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment)
{
Cell cell = new Cell(rowSpan, colSpan);
cell.SetBackgroundColor(backgroundColor);
cell.SetHorizontalAlignment(horizontalAlignment);
cell.SetVerticalAlignment(verticalAlignment);
cell.SetPadding(padding);
cell.SetBorder(border);
cell.Add(paragraph);
return cell;
}
【问题讨论】: