How to automate Microsoft Word 2003 from WPF?

I have a WPF window (using C # as code) that has text fields in it.
I want, when the user presses the print button, I want to take information about these fields and use the Microsoft Word 2003 template. There are several empty fields in the template that will be filled with this information coming from the WPF widow.
How do I automate the word for this?

+3
source share
2 answers

This is easy:

  • COM Microsoft Word 11.0 ( Microsoft.Office.Interop.Word). , Visual Studio Tools Office System / Interop, VS.NET Office , .

  • Word.Application var app = new Word.Application()

  • var doc = app.Documents.Open(...). , # 3.5 . , System.Reflection.Missing.Value .

  • doc.Fields foreach: .Code, .Result .

:

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

, DependencyProperty "LastName", XAML :

<TextBox Text="{Binding LastName}" />
+4

, WPF, . . , :

, . , Wpf, Silverlight.

BTW: COM- .NET COM COM :

Word #

:

Object oMissing = System.Reflection.Missing.Value()
Object oTrue = true;
Object oFalse = false;

, "ref", , null, true false.

(Visual Basic Visual #)

.

+2

Source: https://habr.com/ru/post/1727131/


All Articles