.NET API for Word Processing Documents Creation
Open Source .NET Library to Create, Edit, Search or Merge & Manage Custom Headers/Footers in Microsoft Word files.
What is Word.?
Word is a standalone powerful open source .NET library that gives computer programmers the capability to develop their own applications for managing Word documents. It has included complete support for creating, loading, modifying, and saving Microsoft Word documents in the .NET framework without requiring Microsoft Office Interop Assemblies.
The Word library is very easy to handle and can be integrated into WinForms, WPF, and ASP.NET. The has included full support for various important features opening and reading existing Word documents, adding headers and footers to DOCX, Insert text to DOCX documents, stamping watermarks to DOCX pages, adding text to DOCX documents, handling tables, handling mail merge Word document, working with password protected work documents, insert hyperlinks to Word documents, insert a comment to DOCX document and many more.
Getting Started with Word
First of all, you need to install .NET framework 4.0 and Visual Studio 2010 or later, in order to use Word smoothly.
The recommended way to install is using GitHub
Install Word Library from GitHub
https://github.com/iditectweb/word.git
.NET API to Create & Modify Word Documents
The Word library gives .NET programmers the power to generate as well as modify Word documents inside their own .NET applications. Once the new document is created developers can insert tables, images, and text with just a couple of lines of code. It is also possible to insert one document into other documents or insert content from other documents with ease.
Create New Word File using .NET API
WordDocument document = new WordDocument();
Paragraph para = document.Sections.AddSection().Blocks.AddParagraph();
//add content below
Search and Replace Text in Word Files using C#
Searching plays a major role in every application performance and lets users find things faster. The open source Word library enable computer programmers to search and discover the target text in Microsoft Word document, and highlight the resultant text in Docx file with ease. You can adjust the highlighted format such as color, font format, underline, bold etc. It is also possible to search and replace text in word documents.
How to Search & Highlight Text in Docx Documen va C#?
WordFile wordFile = new WordFile();
WordDocument document = wordFile.Import(File.ReadAllBytes("Sample.docx"));
WordDocumentBuilder builder = new WordDocumentBuilder(document);
//Apply new highlight style
Action action = new Action((state) =>
{
state.HighlightColor = Colors.Yellow;
});
//Highlight all the "Page" text in the document
builder.ReplaceStyling("Page", true, true, action);
File.WriteAllBytes("HighlightText.docx", wordFile.Export(document));
Add Headers and Footers to Word Files via C# API
The open source Word library enables software programmers to add headers and footers inside Microsoft Word documents with just a couple of lines of code. The library supports numerous ways of inserting headers and footers such as adding simple text header/footer, inserting on even/odd pages, adding text and image header/footer, adding header/footer to sections, and so on.
Adding Headers and Footers in Word Documents via C# API
WordFile wordFile = new WordFile();
WordDocument document = wordFile.Import(File.ReadAllBytes("Sample.docx"));
//Add header at the left
Header header = document.Sections[0].Headers.Add();
Paragraph paragraphHeader = header.Blocks.AddParagraph();
paragraphHeader.TextAlignment = Styles.Alignment.Left;
paragraphHeader.Inlines.AddText("simple header");
//Add footer at the right
Footer footer = document.Sections[0].Footers.Add();
Paragraph paragraphFooter = footer.Blocks.AddParagraph();
paragraphFooter.TextAlignment = Styles.Alignment.Right;
paragraphFooter.Inlines.AddText("simple footer");
File.WriteAllBytes("SimpleHeaderFooter.docx", wordFile.Export(document));
Add Text to Word Document via C# API
The easy-to-use Word library has provided a useful feature for inserting Text into MS Word Docx Documents with just a couple of lines of code. It allows developers to customize text size, font style, font weight, and text color. You can also manage your paragraph’s style by setting text alignment, line height, first-line indent, borders & more.
Add Text to Word Document via C# API
WordDocument document = new WordDocument();
WordDocumentBuilder builder = new WordDocumentBuilder(document);
//Set global style for text and paragraph
builder.CharacterState.FontFamily = new ThemableFontFamily("Arial");
builder.CharacterState.FontSize = 16;
builder.ParagraphState.LineSpacing = 1.2;
builder.ParagraphState.FirstLineIndent = 40;
//Insert text using builder directly
builder.InsertText("Nomal text. ");
//Insert one line with text, it will add line break automatically
builder.InsertLine("Nomal line with auto line break. ");
//So the text below will be added in a second paragraph
builder.InsertText("Nomal text. ");
//Insert text using TextInline object
TextInline textInline = new TextInline(document);
textInline.Text = "This text content is using TextInline object. ";
textInline.FontSize = 20;
builder.InsertInline(textInline);