Programmatically figure out whether text overflows table cell

Given a table with a table cell and a paragraph with text in it (and the table option “automatically resize to fit contents” disabled). We would like to be able if the paragraph had enough space to be displayed on one line or if it was wrapped onto two lines. This is something we’d like to inform the user about so that they can change their table layout and make the columns bigger.

I’ve attached a zip file with an example document called “test.docx”. The example.jpg shows the example without needing to open Word. As you can see the value “20000%” doesn’t have enough space on one line and the percentage sign gets moved onto the next line. Is there a way of checking if this behavior occurred, i.e. that the percentage sign was moved because there wasn’t enough space? I hope my explanation was clear enough. (19.9 KB)


Please note that MS Word documents are flow documents. If the text in the table’s cell does not fit on the same line, it will move to the next line. You can check either the text is on the same line or not using Layout APIs of Aspose.Words. We suggest you please check the following DocumentLayoutHelper code example to get the number of lines of table’s cell text. Hope this helps you.

1 Like

Thank you. That worked.


Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.