Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 526509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:47:04+00:00 2026-05-13T08:47:04+00:00

I have a WPF window( using c# as code behind) that has some text

  • 0

I have a WPF window( using c# as code behind) that has some text fields.
What I want is, when the user presses the print button I want to take the information on these fields and use Microsoft word 2003 template. The template has some blank fields to be filled with these info coming from WPF widow.
How would I automate word to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T08:47:04+00:00Added an answer on May 13, 2026 at 8:47 am

    This is easy:

    1. Add a COM reference to the the “Microsoft Word 11.0 Object Library” (or use the Microsoft.Office.Interop.Word assembly). You may have to in install Visual Studio Tools for Office System and/or browse to your the Primary Interop Assembly, depending on your VS.NET and Office versions and what else you have installed.

    2. Create a Word.Application application object var app = new Word.Application()

    3. Open the document with var doc = app.Documents.Open(...). Note that in C# 3.5 or below you must pass all parameters. You can use a variable initialized to System.Reflection.Missing.Value for most of them.

    4. Iterate through doc.Fields using foreach: Read and parse the field’s .Code range, then update the field’s .Result range based on the text box content.

    For example:

    foreach(Field f in doc.Fields)
      if(f.Code.Text.Contains("lastName"))
        f.Result.Text = this.LastName;
      ...
    

    This assumes your data context class has a DependencyProperty “LastName” that is bound from the XAML like this:

    <TextBox Text="{Binding LastName}" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a RichTextBox on a WPF window that I am using kind of
I have a small-scale WPF application using VB.net as the code behind and I
I have a wpf datagrid that has it's columns generated dynamically in code and
In code behind file of the main window of WPF application I have a
I have a C# application using WPF consisting of a single Window holding four
we have a wpf-window with some textboxes and a datagrid. the textboxes descripe a
I have two images on a WPF window that are on top of each
I am using a base Window class in a WPF project. In the code
I have a WinForm UserControl inside a WPF window and the WPF code is
I have some code in my project that reads from and writes into Excel

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.