2

this is the picture of sample i have to create . I want to Create a word document and fill it with text, this document should look like a contract word file. It should have paragraphs with its styles and all sort of things(page for example headers) and in the last page it should have Document seal . Can anyone provide with materials or code ?

    object oCollapseEnd = Word.WdCollapseDirection.wdCollapseEnd;
doc.Paragraphs.Add();
Word.Range objRange = doc.Content;
objRange.Collapse(ref oCollapseEnd);

objRange.Text = "Bold text aligned center" + Environment.NewLine;
objRange.Bold = 1;
objRange.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
objRange.Collapse(ref oCollapseEnd);

objRange.Text = "Regular text aligned left" + Environment.NewLine;
objRange.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
objRange.Bold = 0;
objRange.Collapse(ref oCollapseEnd);

objRange.Text = "Regular text aligned center\nwith something on the next line" + Environment.NewLine;
objRange.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
objRange.Bold = 0;
objRange.Collapse(ref oCollapseEnd);

objRange.Text = "Regular text aligned left, with some ";
objRange.Collapse(ref oCollapseEnd);
objRange.Text = "Bold text here";
objRange.Bold = 1;
objRange.Collapse(ref oCollapseEnd);
objRange.Text = "\nand some regular text on next line" + Environment.NewLine;
objRange.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
objRange.Bold = 0;

found this code but i cant figure things out.

Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
  • Microsoft.Office.Interop.Word; Cant find this using thing as well. can you help me with this reference ? – Luka Cecxladze Dec 26 '18 at 09:37
  • to add the reference follow [this guide](https://stackoverflow.com/questions/28944379/where-can-i-find-microsoft-office-interop-word-dll-2010) – styx Dec 26 '18 at 09:47
  • i added nugets and it fixed i can create a word document now with some texts inside. now i need to add number the pages. – Luka Cecxladze Dec 26 '18 at 09:50
  • "now i need to add number the pages" Please post that as a new question. – Cindy Meister Dec 26 '18 at 14:21
  • 1
    The best approach would be to create the base text and format of the contract as a word template. If you must use interop rather than VBA then use interop to create a document based on the template, modify the document as required (e.g. date, supplier, requirements fields, addition/deletion of paragraphs) and then save (as word or pdf). Creating a document from scratch using interop doesn't seem sensible. – freeflow Dec 26 '18 at 14:51

0 Answers0