当前位置: 首页 > 知识库问答 >
问题:

如何在C#中获取itextSharp表单元格的高度?

汪驰
2023-03-14

我想要得到以下单元格的高度。

cell_logo

CELL_TITLE

PdfPTable table = new PdfPTable(1);
        table.TotalWidth = doc.PageSize.Width - doc.LeftMargin - doc.RightMargin;            
        table.LockedWidth = true;        

        PdfPCell cell_logo = new PdfPCell(imgLog);
        cell_logo.HorizontalAlignment = 1;
        cell_logo.BackgroundColor = new BaseColor(System.Drawing.Color.White);
        cell_logo.PaddingBottom = 20;
        cell_logo.PaddingTop = 50;

        PdfPCell cell_title = new PdfPCell(docName);
        cell_title.HorizontalAlignment = 1;
        cell_title.BackgroundColor = new BaseColor(System.Drawing.Color.White);
        cell_title.PaddingBottom = 50;

        PdfPCell cell_versions = new PdfPCell(ssVersions);
        cell_versions.BackgroundColor = new BaseColor(System.Drawing.Color.White);            
        cell_versions.PaddingTop = 5;
        cell_versions.PaddingBottom = 5;

        PdfPCell cell_dateTime = new PdfPCell(time);
        cell_dateTime.BackgroundColor = new BaseColor(System.Drawing.Color.White);
        cell_dateTime.PaddingTop = 5;
        cell_dateTime.PaddingBottom = 5;

        PdfPCell cell_appVersion =  new PdfPCell(SSCGVersion);
        cell_appVersion.BackgroundColor = new BaseColor(System.Drawing.Color.White);
        cell_appVersion.MinimumHeight = doc.PageSize.Height - doc.TopMargin - doc.BottomMargin - cell_logo.Height - cell_title.Height - cell_versions.Height - cell_dateTime.Height;


        table.AddCell(cell_logo);
        table.AddCell(cell_title);
        table.AddCell(cell_versions);
        table.AddCell(cell_dateTime);
        table.AddCell(cell_appVersion);          

        doc.Add(table); 

共有1个答案

华永逸
2023-03-14

在阅读您的代码示例时,我注意到您已经阅读了这个问题的答案:itextsharp:在一个页面上调整2个元素

您正确设置了表格的宽度,如果要计算高度,这是必需的:

table.TotalWidth = doc.PageSize.Width - doc.LeftMargin - doc.RightMargin;            
table.LockedWidth = true; 

您现在想知道每个单元格的高度。这对你不起作用,因为你看错了地方。不应该查看单元格的高度,应该查看单元格所属行的高度。单元格的高度并不重要,重要的是行的高度。

float h1 = table.GetRowHeight(0);
float h2 = table.GetRowHeight(1);
table.SetExtendLastRow(true, true);
 类似资料:
  • 注意:对于.xls类型的excel文件,我使用的是ExcelLibrary.dll库,可以使用下面的代码轻松获取单元格的数据类型 但在Spreadsheetlight中没有类似的方法。

  • 问题内容: 在Selenium 2.0中,我不知道如何遍历网页中的HTML表。在selenium2.0 javadoc中,我找到了两个类“ TableFinder”和“ TableCellFinder”,但找不到任何示例。 我想做这样的事情: 如何从每个表格单元格中获取文本? 问题答案: 感谢您的早日答复。 我找出了使用硒2.0类的解决方案。

  • 我构造了一个从数据帧中提取一行条件: 现在我想从一个特定列中取一个值:

  • 有人能给我一个解决方案,我可以在单元格为空时读取应用到单元格的样式吗? 谢了。

  • 我已经能够在VB中使用iTextSharp创建PDF。net代码,看起来几乎完全符合我的要求。然而,我使用一个包含一列和多行的表来显示通过使用块和短语组合在一起的长文本字符串。有些区块包含带下划线的文本。当一个短语中有带下划线的文本时,整个单元格需要以灰色突出显示,我使用PdfPCell的BackgroundColor属性来实现这一点。 我遇到的问题是,下划线落在单元格边界之外(突出显示之外)。我

  • 问题内容: 实际上,我使用的是xlrd模块0.8版本,但我不知道如何读取单元格属性,例如背景色,字体以及单元格是否被锁定。 我尝试使用 它引发一个错误,指出在读取时需要设置格式化信息,但是如果我有该参数,则表明它仍未实现。 是否有另一个模块,或者该模块本身如何读取单元格属性? 问题答案: 以下内容使用xlrd 0.7.6版对我有效: 是XF类的实例;参见https://secure.simplis