Skip to content

Generate a word document with mvvm and wpf

Yagmour maima

Asked Feb 2, 2014, 9:31 PM EST2 answers
Share
LinkedInX
Hi,
I' m a beginner in wpf and I faced a problem in my project.
I have a datagirid and I want to export a selected row values to a  word document a model.
if someone can help me :) 

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    You will have to take a template based document generation approach. This means that you will need to create/program a solution that will allow you to create a template Word document with tagged content (placeholders/repeating blocks) and then process it in a .NET application. In order to create such a solution you will have to employ a technology/framework/library that will allow you to parse such template document. You can mainly choose between Open XML SDK or Office COM (not recommended).

    You can also take a look at this 3rd party mail merge toolkit for .NET which already does exactly what you need and is also pretty affordable.
    0
  • 0
    Hi, yes Jasna is right. You need to define placeholders in your word document and then you can import the data from the DataGridView.SelectedRows into those placeholders.
    This is often accomplished with a MergeFields (INSERT -> Quick Parts -> Field... -> MergeField).
    Anyway if interested I would recommend you to check out this 3rd party .NET component for Word files. It has a really simple interface that abstracts the word's DOCX format, so you can avoid hassling and learning about that format.
    If interested then here is how you can create a new Word document in C# and here is how you can execute a mail merge process in C#.
    0