| PDFsharp & MigraDoc Forum https://forum.pdfsharp.net/ |
|
| Get text of a Paragraph https://forum.pdfsharp.net/viewtopic.php?f=2&t=2728 |
Page 1 of 1 |
| Author: | weilah [ Mon Feb 03, 2014 4:27 pm ] |
| Post subject: | Get text of a Paragraph |
Hi there, I'm trying to get the text set in a paragraph. I set the text this way: Code: parContent = cellContent.AddParagraph("Project manager:") and I'm looking for a property like: Code: parContent.text or something that returns me "Project manager:". Thank you! |
|
| Author: | Thomas Hoevel [ Mon Feb 03, 2014 4:52 pm ] |
| Post subject: | Re: Get text of a Paragraph |
Hi! In this code snippet, row is a table row: Code: Paragraph p = row.Cells[cell].Elements[idxElement] as Paragraph; if (p != null && p.Elements.Count > 0) { Text t = p.Elements.First as Text; if (t != null) { return t; } } Elements can contain other objects (e.g. FormattedText). If you only call "AddParagraph(string)" and only once for each cell, then the code above will work (set idxElement to 0). |
|
| Author: | weilah [ Tue Feb 04, 2014 9:42 am ] |
| Post subject: | Re: Get text of a Paragraph |
Hey, I'm sorry, I didn't realize that "cellContent" was in my snippet and that's why I didn't clarify where does actually come from, and you had to figure it out. Anyway, your snippet works for me. I just added a Code: t.Content to get the string. One more question, will it be the same if instead of adding the paragraph to a table cell I add it to a document section and with a predefined style? Like: Code: paragraphDesc = section.AddParagraph("Project description", "MyHeading2") Where section is a Section of the Document. And "MyHeading2" an already definded style. Thank you very much. |
|
| Author: | Thomas Hoevel [ Tue Feb 04, 2014 9:55 am ] |
| Post subject: | Re: Get text of a Paragraph |
Section or Cell - both have member Elements with the Paragraphs etc. |
|
| Page 1 of 1 | All times are UTC |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|