//Create a new Word document
WordDocument document = new WordDocument();
//Add new section to the Word document
IWSection section= document.AddSection();
//Set the page margins for the section
section.PageSetup.Margins.All = 72;
//Add new paragraph to the document
IWParagraph paragraph = section.AddParagraph();
//Get the width of the document body excluding the margins.
//This width should be set as the tab stop position to get the line till the right margin of the page
float tabWidth = section.PageSetup.ClientWidth;
//Append the text to the paragraph
paragraph.AppendText("Name: ");
//Add a tab to the paragraph specifying the tab width, tab justification, and tab leader
paragraph.ParagraphFormat.Tabs.AddTab(tabWidth, TabJustification.Left, TabLeader.Single);
//Append tab to the paragraph
paragraph.AppendText("\t");
paragraph = section.AddParagraph();
paragraph.AppendText("Last Name: ");
paragraph.ParagraphFormat.Tabs.AddTab(tabWidth, TabJustification.Left, TabLeader.Single);
paragraph.AppendText("\t");
//Save the Word document
document.Save("Sample.docx");
//Close the document instance
document.Close(); |