How do you mail merge a word document in c#

后端 未结 3 513
故里飘歌
故里飘歌 2020-12-30 09:15

What I\'m trying to achieve

In my c# application I would like to generate a report (word document) from data in my application, I figured that the best way to do t

3条回答
  •  萌比男神i
    2020-12-30 09:39

    I am also using the same thing but I have more complexity. I have to check the if condition also. In word template file { IF «Installment» = Monthly "then the table will appear" "nothing to show" }

    when I use the above code shared in the answer. and for if condition in c# I have written

    Range rngFieldCode = myMergeField.Code;
                String fieldText = rngFieldCode.Text.Trim();
                if (fieldText.ToUpper().StartsWith("IF"))
                {
                    myMergeField.UpdateSource();}
    

    so the output is like

    { IF Monthly = Monthly "then table will appear" "nothing to show" }

    but the desired output is only "then the table will appear".

提交回复
热议问题