删除表格单元格之间的空白

罗伯特·史密斯

我正在使用ITextSharp 5.5.7。我有以下代码,一切正常。但是,我需要删除每个单元格之间的空白。我尝试了所有发现的建议,但仍然没有删除空格。这是代码:

private PdfPTable createTable()
        {

            // Table (No border, just to hold all objects)
            PdfPTable sheetTable = new PdfPTable(1);
            sheetTable.WidthPercentage = 100;
            sheetTable.DefaultCell.Border = iTextSharp.text.Rectangle.NO_BORDER;
            sheetTable.SpacingBefore = 0f;
            sheetTable.SpacingAfter = 0f;

            // Add Heading One
            sheetTable.AddCell(createHeadingOne());

            // Add Heading two
            sheetTable.AddCell(createHeadingTwo());

            return sheetTable;

        }


        private PdfPTable createHeadingOne()
    {

        PdfPCell cell = new PdfPCell();

        PdfPTable headingTable = new PdfPTable(2);

        // Set widths of columns
        int[] headingTablewidths = { 50, 50 }; // percentage
        headingTable.SetWidths(headingTablewidths);

        cell = new PdfPCell(new Phrase("col1row1", FontFactory.GetFont(FontFactory.HELVETICA, 8, BaseColor.BLACK)));
        headingTable.AddCell(cell);

        cell = new PdfPCell(new Phrase("col2row1", FontFactory.GetFont(FontFactory.HELVETICA, 8, BaseColor.BLACK)));
        headingTable.AddCell(cell);

        return headingTable;

    }

    private PdfPTable createHeadingTwo()
    {

        PdfPCell cell = new PdfPCell();

        PdfPTable headingTable = new PdfPTable(2);

        // Set widths of columns
        int[] headingTablewidths = { 50, 50 }; // percentage
        headingTable.SetWidths(headingTablewidths);

        cell = new PdfPCell(new Phrase("col1row2", FontFactory.GetFont(FontFactory.HELVETICA, 8, BaseColor.BLACK)));
        headingTable.AddCell(cell);

        cell = new PdfPCell(new Phrase("col2row2", FontFactory.GetFont(FontFactory.HELVETICA, 8, BaseColor.BLACK)));
        headingTable.AddCell(cell);

        return headingTable;

    }

更新#1蓝线是我需要删除间距的区域:

在此处输入图片说明

更新#2,已修复。这是Bruno提供的代码:

PdfPCell cell;
cell = new PdfPCell(createHeadingOne());
cell.Padding = 0;
sheetTable.AddCell(cell);
cell = new PdfPCell(createHeadingTwo());
cell.Padding = 0;
sheetTable.AddCell(cell);
布鲁诺·洛瓦吉(Bruno Lowagie)

我会这样解决:

PdfPCell cell;
cell = new PdfPCell(createHeadingOne());
cell.Padding = 0;
sheetTable.AddCell(cell);
cell = new PdfPCell(createHeadingTwo());
cell.Padding = 0;
sheetTable.AddCell(cell);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

删除表格单元格末尾的空白

如何删除表格单元格中的空白空间?

如何删除Google表格中列的空白单元格?

删除空白单元格

删除空白单元格

空白表格视图单元格

修剪表格单元格中的空白

如何删除表格的单元格边框?

减少图像宽度后从表格单元格中删除空白

Google表格公式帮助:如果参考单元格为空白,则单元格为空白

删除UICollectionView的单元格之间的空间

NSTableView删除表格视图边框和单元格之间的填充/空格

如何在Material-ui中删除表格中单元格之间的线

如何在Edge浏览器中删除表格单元格之间的白色间距

计算一列中非空白单元格之间的连续空白单元格

在Google表格中,是否有一种方法可以计数空白单元格,但前提是它们位于具有值的单元格之间?

Google表格RegexReplace和空白单元格

自定义表格单元格负载为空白

在HTML表格的空白单元格中建立链接

垂直求和,直到Google表格上的空白单元格

表格视图单元格为空白Swift

计算 Excel/Google 表格中的非空白单元格

基于向量替换表格的单元格(空白单元格和没有字典的除外)

新表格视图单元格显示为空白单元格

Google Apps脚本,用于发现Google表格的两列之间的差异,而忽略空白单元格和多个实例

空白单元格和值为=“”的单元格之间的差异

宏取消合并空白单元格之间的单元格

使用arrayformula连接空白单元格之间的范围

如何使用单元格之间的空白扩展动态范围?