link is broken. also, could you please provide a simple example? Thanks!
Hello @awais.hafeez, would you be so kind to provide a simple example on how to check if a cell will wrap text? Thanks!
You can use the CellFormat.WrapText property. If you set it to true, then cell will wrap text.
@awais.hafeez Thanks for the response. But I’m asking for checking whether a cell is wrapped and not enable/disabling it to wrap. For example if I have a cell and it contains a text too long that caused it wrap, which property or function should I use to know that it actually wrapped?
I think, you can build logic on the following code to calculate number of lines in Paragraphs. If a Paragraph in Cell has more than one line, then it is wrapped text:
Document document = new Document("D:\\Temp\\input.doc");
var collector = new LayoutCollector(document);
var it = new LayoutEnumerator(document);
foreach (Paragraph paragraph in document.GetChildNodes(NodeType.Paragraph, true))
{
var paraBreak = collector.GetEntity(paragraph);
object stop = null;
var prevItem = paragraph.PreviousSibling;
if (prevItem != null)
{
var prevBreak = collector.GetEntity(prevItem);
if (prevItem is Paragraph)
{
it.Current = collector.GetEntity(prevItem); // para break
it.MoveParent(); // last line
stop = it.Current;
}
else if (prevItem is Table)
{
var table = (Table)prevItem;
it.Current = collector.GetEntity(table.LastRow.LastCell.LastParagraph); // cell break
it.MoveParent(); // cell
it.MoveParent(); // row
stop = it.Current;
}
else
{
throw new Exception();
}
}
it.Current = paraBreak;
it.MoveParent();
// We move from line to line in a paragraph.
// When paragraph spans multiple pages the we will follow across them.
var count = 1;
while (it.Current != stop)
{
if (!it.MovePreviousLogical())
break;
count++;
}
const int MAX_CHARS = 16;
var paraText = paragraph.GetText();
if (paraText.Length > MAX_CHARS)
paraText = $"{paraText.Substring(0, MAX_CHARS)}...";
Console.WriteLine($"Paragraph '{paraText}' has {count} line(-s).");
}
Hope, this helps.