Search code examples
migradoc

Check if MigraDoc font of a row is bold or not


I have a MigraDoc Table with multiple rows . I am trying to find if a particular row is bold or not

   if(table.Rows[0].Font.bold ==font.bold)
   {
    Do Something
    }

Idea is to change the colour of that row to a specific one.


Solution

  • There are many ways to set font attributes with MigraDoc. What do you want to happen if some columns are bold and some are not? Or if some columns contain both bold and regular text?

    The clean approach would be determining the color of the row when you add contents to it. Each MigraDoc document element has a Tag member of type object that you can use for your own purposes. When filling the row you can set the color directly. Or you can use the Tag member to mark the row as "important" and set the colors for important rows at a later stage.

    Untested code that may work - and since there are several ways to make text bold, this will work only if the code that fills the rows also sets the Bold property to true:

    if (table.Rows[0].Format.Font.Bold == true)
    {
        Do Something
    }
    

    The above will not work if a row is "bold", but the boldness comes from a Style or is set via paragraph properties.
    IMHO using the Tag member is a cleaner way.