C# Office.Interop How to select Text and apply template

  • Thread starter Thread starter Vadim199
  • Start date Start date
V

Vadim199

Guest
Hello,

I am new to C# and am writing a small application with the Microsoft.Office API which can insert documents into a new one and edit the newly create document. I am currently working on selecting all text and changing the font-family and restart numbered lists with the help of these functions:

List.ApplyListTemplate(ListTemplate, Object, Object) Method (Microsoft.Office.Interop.Word)

Editor.SelectAll Method (Microsoft.Office.Interop.Word)

But I don't know how to use them

var realPathCover = "\\Document";
//Object of the end of the document
Object endOfDoc = "\\endofdoc";
//Object as infill for missing values
Object missing = System.Reflection.Missing.Value;
//Objects of true and false
Object oTrue = true;
Object oFalse = false;
//Creating the objects Word and Document
Word._Application word = new Word.Application();
Word._Document doc = new Word.Document();

//Making the application visible
word.Visible = true;
//Adding a new Document to the Application
doc = word.Documents.Add(ref missing, ref missing, ref missing, ref missing);
//Setting up the paper
doc.PageSetup.FooterDistance = word.CentimetersToPoints(1);
doc.PageSetup.HeaderDistance = word.CentimetersToPoints(1);
doc.PageSetup.DifferentFirstPageHeaderFooter = -1;


object gotoPage = Word.WdGoToItem.wdGoToLine;
object gotoLast = Word.WdGoToDirection.wdGoToLast;
Console.WriteLine(realPathCover);
//HERE COMES THE FIRST PAGE
doc.Bookmarks.get_Item(ref endOfDoc).Range.InsertFile(realPathCover, ref missing, ref oFalse, ref oFalse, ref oFalse);

Word.Editor editor = new Editor();
editor.SelectAll();

Word.ListTemplate template = doc.ListTemplates.Add(ref oTrue, ref missing);
word.Selection.Range.ListFormat.ApplyListTemplate(template, ref oFalse);


Thanks in advance and appreciate your help

Continue reading...
 
Back
Top