Thanks for your inquiry.
The height of a table row is controlled using height and height rule
properties. These can be set differently for each row in the table which
allows for wide control over the height of each row. Please read
following documentation link for your kind reference. https://docs.aspose.com/words/net/applying-formatting/
Problem is, that I need to set “RowFormat.HeightRule” to “Exactly” and set height equal to each row.
Idea was - at first I set “Auto”, then chech the height of each row. Then take maximum and set it to each row with setting “Exactly”
Problem is, that it does not matter if row has 100 text lines - it still says 5 pixel (the initial height, with setting “Auto”) in backend code. If I open it in word later - height is much bigger than 5 px.
Is there any way to find real (calculated, expanded by text) height of the row/cell?
Thanks for your inquiry. Your requirement is about MS Word’s feature ‘Distribute Rows Evenly’. Unfortunately, Aspose.Words does not support
the requested feature at the moment. However, we have already logged this
feature request as WORDSNET-10671 in our issue tracking system.
You will be notified via this forum thread once this feature is
available.
Please use following code example to achieve your requirements. Hope this helps you.
Document doc = new Document(MyDir + "example.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
int i = 1;
foreach (Table table in doc.GetChildNodes(NodeType.Table, true))
{
foreach (Row row in table.Rows)
{
row.RowFormat.HeightRule = HeightRule.Auto;
row.FirstCell.LastParagraph.AppendChild(new Run(doc));
builder.MoveTo(row.FirstCell.FirstChild);
builder.StartBookmark("Bookmark" + i);
builder.MoveTo(row.FirstCell.LastParagraph.LastChild);
builder.EndBookmark("Bookmark" + i);
i++;
}
}
LayoutCollector layoutCollector = new LayoutCollector(doc);
LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
Double height = 1.0;
Double rowheight = 1.0;
var collection = doc.GetChildNodes(NodeType.Row, true);
foreach (Row row in collection)
{
BookmarkStart bmStart = (BookmarkStart)row.FirstCell.GetChild(NodeType.BookmarkStart, 0, true);
if (bmStart == null)
continue;
var renderObject = layoutCollector.GetEntity(bmStart);
layoutEnumerator.Current = renderObject;
RectangleF location1 = layoutEnumerator.Rectangle;
renderObject = layoutCollector.GetEntity(bmStart.Bookmark.BookmarkEnd);
layoutEnumerator.Current = renderObject;
RectangleF location2 = layoutEnumerator.Rectangle;
rowheight = location2.Y - location1.Y;
if (rowheight > height)
height = rowheight;
else if (rowheight == 0)
height = location1.Height;
}
foreach (Row row in collection)
{
row.RowFormat.HeightRule = HeightRule.AtLeast;
row.RowFormat.Height = height;
}
doc.Save(MyDir + "Out.docx");
Hi,
Shared code was just a workaround. This feature will be available as soon as the issue WORDSNET-10671 is fixed. We are sorry for the inconvenience.
Best Regards,
I see there was similar message on 2014-08. Is there posibility to get that feature in the nearest month? This is required in the report, which will be released soon
Hi,
This feature was postponed because there was only one request for this feature and our development team had more demanded features and issues on higher priority.
A request to share the ETA of this feature has been forwarded to our development team. We will update you as soon as our development team share the ETA.
Best Regards,
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.