Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# iTextSharp表格单元colspan_C#_Itext - Fatal编程技术网

C# iTextSharp表格单元colspan

C# iTextSharp表格单元colspan,c#,itext,C#,Itext,我有一张桌子,所有的东西都打印出来了,但只有一个问题。 即使我设置了正确的列,它也只是打印出每列的默认宽度 在本例中,我尝试设置一个float[](在实例化表时)以查看是否可以设置每列的宽度(即使Cell对象的colspan应该已经处理了它),但即使如此,它也没有改变。以前,我有整数作为列数,但结果是一样的。我需要一些澄清,因为部分文件已经过时 doc.Add(NewTable(new float[4] { 0, 0, 0, 0 }, new float[3] { 1, 5, 5 }, 250,

我有一张桌子,所有的东西都打印出来了,但只有一个问题。 即使我设置了正确的列,它也只是打印出每列的默认宽度

在本例中,我尝试设置一个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;
        }
doc.Add(新表(新浮点数[4]{0,0,0,0},新浮点数[3]{1,5,5},250,0,-1,200,150,
新名单(){
新单元格(新段落(“N.ºdo Auto:”).SetFont(FontBold),ColorGray,新SolidBorder(1),1,1,2.5f,水平对齐。左侧,垂直对齐。中间),
新单元格(新段落(“fdgdfgdfg”)。设置字体(FontRegular),颜色灰色,新的SolidBorder(1),1,2,2.5f,水平对齐。左侧,垂直对齐。中间),
新单元格(新段落(“数据:”).SetFont(FontBold),颜色灰色,边框。无边框,1,1,2.5f,水平对齐。左侧,垂直对齐。中间),
新单元格(新段落(DateTime.Now.ToString(“dd/MM/yyyy”)).SetFont(FontRegular),彩色灰色,边框。无边框,1,2,2.5f,水平对齐。左侧,垂直对齐。中间),
NewCell(新段落(“Morada:”).SetFont(FontBold),颜色灰色,边框。无边框,1,1,2.5f,水平对齐。左侧,垂直对齐。中间),
新单元格(新段落(“fdgdfgdfg”)。SetFont(FontRegular),彩色灰色,边框。无边框,1,2,2.5f,水平对齐。左侧,垂直对齐。中间)
}));
/// 
///创建一个新表
/// 
///用于设置表格填充(顶部、右侧、底部、左侧)的值数组。
///一个值数组,用于指定行中每个单元格存储的列数。
///桌子的宽度。
///要从中开始写入的表行。
///要结束写入的表行(-1适用于所有行)。
///桌子的水平位置(从左下角)。
///桌子的垂直位置(从左下角)。
///要添加到表中的单元格列表。
/// 
私有静态表NewTable(float[]填充,float[]点列宽,float宽度,int rowStart,int rowEnd,float horizontalPosition,float verticalPosition,列表单元格)
{
Table Table=新表(点列宽度);
表.设置填充物(填充物[0]、填充物[1]、填充物[2]、填充物[3]);
foreach(单元中的单元)
表2.AddCell(cell);
表.设置固定位置(水平位置、垂直位置、宽度);
返回表;
}
/// 
///创建一个新单元
/// 
///包含内容的段落对象。
///单元格的背景色。
///要应用于单元格的边框。
///单元格将在表中复制的行数。
///单元格将在表中复制的列数。
///单元格的填充物。
///水平路线的枚举值。例:水平对齐。左
///垂直路线的枚举值。例:垂直对中
/// 
专用静态单元格NewCell(段落段落、颜色背景颜色、边框、int rowSpan、int colSpan、浮动填充、水平对齐水平对齐垂直对齐)
{
Cell Cell=新单元格(rowSpan、colSpan);
cell.SetBackgroundColor(背景色);
单元格。设置水平对齐(水平对齐);
细胞垂直排列(垂直排列);
单元格。设置填充(填充);
单元格顺序(边框);
添加(第段);
返回单元;
}

您传递了
float[]pointColumnWidths
,但它没有在任何地方使用

试试这个:

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;
}
private static Table NewTable(float[]填充、float[]点列宽、float宽度、int rowStart、int rowEnd、float horizontalPosition、float verticalPosition、列表单元格)
{
Table Table=新表(点列宽度);
表.设置填充物(填充物[0]、填充物[1]、填充物[2]、填充物[3]);
foreach(单元中的单元)
表2.AddCell(cell);
表.设置固定位置(水平位置、垂直位置、宽度);
返回表;
}

您传递了
float[]pointColumnWidths
,但它没有在任何地方使用

试试这个:

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;
}
private static Table NewTable(float[]填充、float[]点列宽、float宽度、int rowStart、int rowEnd、float horizontalPosition、float verticalPosition、列表单元格)
{
Table Table=新表(点列宽度);
表.设置填充物(填充物[0]、填充物[1]、填充物[2]、填充物[3]);
foreach(单元中的单元)
表2.AddCell(cell);
表.设置固定位置(水平位置、垂直位置、宽度);
返回表;
}

谢谢。问题在于百分比。从他们的例子中,我认为它的工作原理类似于bootstrap中的colspan,其中总共有12列。不再有SetTotalWidth方法。我使用的是7.1.2版。但这是我的错。我在表构造函数中有float[]pointColumnWidths。当我试着看看哪里出了问题时,我忘了纠正它。所以,我在我的主要帖子中纠正了它。也修改一下你的答案,这样我就可以接受你的答案了。我再次感谢你@大幸子,谢谢你的指导,代码已经更改,不客气。顺便说一句,我刚刚意识到浮子