/// <summary> /// Creates a Word document with plain text. /// </summary> /// <param name="filePath">The path to the file to be created.</param> /// <param name="contentToWrite">The content to be added to the document.</param> public static void WriteWordDocument(string filePath, StringBuilder contentToWrite) { if (Path.GetExtension(filePath) == ".doc" || Path.GetExtension(filePath) == ".docx") { Word.Application a = new Word.Application(); a.Visible = false; object missing = System.Reflection.Missing.Value; Word.Document doc = a.Documents.Add(ref missing, ref missing, ref missing, ref missing); WordManager wm = new WordManager(); wm.AddParagraph(doc, "Lorem ipsum"); doc.Content.Text += contentToWrite.ToString(); wm.AddHeader(doc, "headertext"); wm.AddFooter(doc, "footertext"); string imagePath = @"C:\Users\gebruiker\Desktop\PrijsManager.png"; //wm.AddFooterImage(doc, imagePath); var start = doc.Content.Start; var end = doc.Content.End; doc.Range(start, end).Font.Name = "Calibri"; doc.Range(start, end).Font.Size = 11; doc.SaveAs(filePath); doc.Close(ref missing, ref missing, ref missing); doc = null; a.Quit(ref missing, ref missing, ref missing); a = null; Console.WriteLine(filePath + " is successfully created."); } }