Hi,
How to create word document with add styles by using c# language..
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Selva GanapathyRank #560 · 4.3K reputationPosted Feb 19, 2014, 10:12 PM EST
You can create a Word Document in C# using "Microsoft.Office.Interop.Word" as like as following code snippet.
private Microsoft.Office.Interop.Word.ApplicationClass newWord= new Microsoft.Office.Interop.Word.ApplicationClass();
Also to edit its style use "Range" option provided in the same class to insert our data as per our desire.
Regards,
Selva Ganapathy K
Jasna Kozelj13 reputationPosted Mar 10, 2014, 10:46 AM EDT
Megan Foster18 reputationPosted Feb 5, 2015, 10:52 PM EST
Also here is a small demonstration sample how to add and use styles:
// Create new document. DocumentModel document = new DocumentModel(); // Create paragraph style. ParagraphStyle customParagraphStyle = new ParagraphStyle("My Paragraphs"); customParagraphStyle.ParagraphFormat.Alignment = HorizontalAlignment.Center; // Create character style. CharacterStyle customCharacterStyle = new CharacterStyle("My Characters"); customCharacterStyle.CharacterFormat.Bold = true; // Add style to the document. document.Styles.Add(customParagraphStyle); document.Styles.Add(customCharacterStyle); // Add document's content and use the above custom styles. document.Sections.Add( new Section(document, new Paragraph(document, new Run(document, "Hello World") { CharacterFormat = { Style = customCharacterStyle } }) { ParagraphFormat = { Style = customParagraphStyle } })); // Save document to file. document.Save("Sample.docx");