Search code examples
c#migradoc

Getting a paragraph value in MigraDoc


I've got a line here :

Paragraph par = row.Cells[0].AddParagraph("Value");

Is there a way to get the text value from par? I have tried par.GetValue() but that didn't work


Solution

  • Paragraphs can contain a mix of text with different sizes, fonts, attributes along with images and other things.

    Here's a code snippet that gets the first text element:

    if (para.Elements.Count > 0)
    {
        Text t = para.Elements[0] as Text;
        if (t != null)
        {
            string s = t.Content;
            ...
        }
    }
    

    You know what your code adds to the paragraph, so you should know what you have to extract.

    I do not know what you are trying to do. Every MigraDoc document object has a Tag member for custom use. You can assign any object (including string) to this Tag.