using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Collections;
using System.Threading;
using Word;
object start = 0;
object end = 0;
Word.Range range = Word_doc.Range(ref missing,ref missing);
// add text to the doc -- this contains some deliberate misspellings so that we can correct them in a short while
range.Text="Microsoft Word Interoperability Sample\n\nInntroduction:\n\nMicrosoft .NET will alow the creation of truly distributed XML Web services. These services will integrate and collaborate with a range of complementary services to work for customers in ways that today's internet companies can only dream of. Microsoft .NET will drive the Next Generation Internet and will shift the focus from individual Web sites or devices connected to the Internet, to constellations of computers, devices, and services that work together to deliver broader, richer solutions.\nFor more info go to:\n ";
// Wait so the starting state can be admired
Thread.Sleep(2000);
// Format the title
Word.Font fc= new Word.Font();
try
{
Console.WriteLine("Formatting the title");
start = 0; end = 40;
range=Word_doc.Range(ref start, ref end);
range.Font.Size=24;
range.Font.Bold=1;
range.Font.Color=Word.WdColor.wdColorGray30;
start = 40; end = 54;
range=Word_doc.Range(ref start, ref end);
range.Font.Size=14;
}
catch(Exception e)
{
Console.WriteLine(" Font exception:{0}", e.ToString());
}
// Wait so the new formatting can be appreciated
Thread.Sleep(3000);
// Add a caption to the window and get it back
Word.Window myWindow = Word_App.ActiveWindow;
myWindow.Caption = "Managed Word execution from C# ";
string gotCaption = myWindow.Caption;
if (gotCaption.Equals("Managed Word execution from C# "))
{
Console.WriteLine("Caption assigned and got back");
return_Result = 1;
}
Thread.Sleep(2000);
// define the selection object, find and replace text
Word.Selection mySelection = myWindow.Selection;
Word.Find myFind = mySelection.Find;
object findText = "alow";
object replaceText ="allow";
// Find "alow" and replace with "allow"
try
{
myFind.Execute(ref findText,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref replaceText,ref missing,ref missing,ref missing,ref missing,ref missing);
}
catch(Exception e)
{
Console.WriteLine(e);
}
Thread.Sleep(2000);
Console.WriteLine(myFind.Text + " has been corrected");
try
{
start = 65; end = 69;
range=Word_doc.Range(ref start, ref end);
Console.WriteLine("The color of .NET is being changed");