How to get table row rendered hight in inch

hi ,
i am using aspose.word 21.8.0.

i want to get the the first row’s rendering row height.

Nos.docx (12.7 KB)
my c# codes are:

var fileFullname = @"O:\Nos.docx";
var document = new Aspose.Words.Document(fileFullname);
var allTables = document.GetChildNodes(NodeType.Table, true).ToList().Select(x => x as Table).ToList();
var table = allTables.First();

var row = table.Rows[0];
var rowHeight = row.RowFormat.Height;

the RowForamt.Height just provide the format height. is there any api to get the rendering row height(the unit is inch)?

thank you.

@vs6060_qq_com You can use LayoutCollector and LayoutEnumerator to calculate actual row height. For example see the following code:

Document doc = new Document(@"C:\Temp\in.docx");
LayoutCollector collector = new LayoutCollector(doc);
LayoutEnumerator enumerator = new LayoutEnumerator(doc);

Table table = doc.FirstSection.Body.Tables[0];
Row row = table.Rows[0];

// move enumerator inside the row.
enumerator.Current = collector.GetEntity(row.FirstCell.FirstParagraph);
// move enumerator to the row level
while (enumerator.Type != LayoutEntityType.Row)
    enumerator.MoveParent();
// get actual row height in points.
double rowHeightPoints = enumerator.Rectangle.Height;
// Convert to inches.
double rowHeightInches = ConvertUtil.PointToInch(rowHeightPoints);

that’s great,i tested the above codes,it works fine to me.

thank you very much.

1 Like