您可以使用 Aspose.Words 中的以下方法来获取固定行高单元格在指定字体及字体大小下,能容纳的行数:

  1. 首先,创建一个 Document 对象并打开您需要进行操作的文档。
Document doc = new Document('input.docx');
  1. 获取您需要进行操作的表格,可以使用 Document 对象中的 GetChildNodes 方法来获取所有的表格,然后通过索引获取您需要的表格。
Table table = doc.GetChildNodes(NodeType.Table, true)[0] as Table;
  1. 获取您需要进行操作的单元格,可以使用 Table 对象中的 Rows 和 Cells 属性来获取相应的单元格。
Cell cell = table.Rows[0].Cells[0];
  1. 设置相应的字体及字体大小。
Font font = new Font('Arial', 12);
  1. 使用 Aspose.Words 中的 LayoutEnumerator 对象来获取单元格在指定字体及字体大小下可容纳的行数。
LayoutEnumerator enumerator = new LayoutEnumerator(doc);

enumerator.Current = cell.FirstParagraph;

double cellHeight = cell.CellFormat.Height;

int rowCount = 0;

while (enumerator.MoveNext() && enumerator.Rectangle.Height <= cellHeight)
{
    if (enumerator.Rectangle.Bottom > cellHeight)
        break;

    if (enumerator.Rectangle.Height == 0)
        continue;

    if (enumerator.Rectangle.Bottom <= cellHeight)
        rowCount++;
}

Console.WriteLine('能容纳的行数为:' + rowCount);
  1. 最后关闭文档。
doc.Save('output.docx');

以上就是使用 Aspose.Words 来获取固定行高单元格在指定字体及字体大小下,能容纳的行数的步骤。

C# Aspose.Words: 计算固定行高单元格容纳行数

原文地址: https://www.cveoy.top/t/topic/nKcV 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录