Introduction

If you are looking for a solution to programmatically create DOCX in C# or VB.Net, you are in the right place!


Document .Net is 100% managed C# assembly (SautinSoft.Document.dll) which gives you API to generate Office Open XML (DOCX) documents. 

Your .Net app will be able to create DOCX documents with any desired formatting, such as:

The library is absolutely standalone and does not require Microsoft Office or any others.

Main Functions

The library is absolutely standalone and does not require Microsoft Office or any others.

Performance

At a machine with Intel Core i5-3337U and 4GB of RAM the Document .Net generates a simple DOCX document (one page filled by formatted text) without saving it to HDD:

Implementation and code samples

To get the full set of API to operate with DOCX, you have to only add a reference to "Document.Net".

1. Let's see how easy to create DOCX document in C# application:

 

C#
Edit|Remove
// Let's create a simple DOCX document. 
DocumentCore docx = new DocumentCore(); 
 
docx.Content.End.Insert("Hello my Friend!"new CharacterFormat() { Size = 14, FontName = "Arial"});

2. Let's add a table (2x3) in DOCX using for-loop:

C#
Edit|Remove
// Let's create a simple DOCX document. 
DocumentCore docx = new DocumentCore(); 
 
// Add a new section 
Section s = new Section(docx); 
docx.Sections.Add(s); 
 
 
// Let's create a plain table: 2x3. 
Table t = new Table(docx);             
 
// Add 2 rows.for (int r = 0; r < 2; r++) 
{ 
    TableRow row = new TableRow(docx); 
     
    // Add 3 columns.for (int c = 0; c < 3; c++) 
    { 
        TableCell cell = new TableCell(docx); 
 
        // Set some cell formatting 
        cell.CellFormat.Borders.SetBorders(MultipleBorderTypes.Outside, BorderStyle.Single, Color.Blue, 1.0); 
        cell.CellFormat.PreferredWidth = new TableWidth(60, TableWidthUnit.Point); 
 
 
        row.Cells.Add(cell); 
 
        cell.Content.Start.Insert(String.Format("[{0}, {1}]", r, c)); 
    } 
    t.Rows.Add(row); 
} 
// Add this table to the current section. 
s.Blocks.Add(t);

3. If you want to add an image in DOCX in your .Net app:

C#
Edit|Remove
// Let's create a simple DOCX document. 
DocumentCore docx = new DocumentCore(); 
 
// Add a new section 
Section s = new Section(docx); 
docx.Sections.Add(s); 
 
// Add the image as a shape with coordinates. 
Picture pict1 = new Picture(docx, "image1.jpg"); 
 
FloatingLayout fl = new FloatingLayout( 
    new HorizontalPosition(10, LengthUnit.Millimeter, HorizontalPositionAnchor.Page), 
    new VerticalPosition(10, LengthUnit.Millimeter, VerticalPositionAnchor.TopMargin), 
    new Size(7070)); 
DrawingElement drawingElement = new DrawingElement(docx, fl, pict1); 
s.Content.End.Insert(drawingElement.Content);

Source Code Files

Related Links:


Website: www.sautinsoft.com
Product Home: Document.Net
Download: Document.Net

 

Requrements and Technical Information

 Requires only .Net 4.0 or above. Our product is compatible with all .Net languages and supports all Operating Systems where .Net Framework can be used.

Note that «Document .Net» is entirely written in managed C#, which makes it absolutely standalone and an independent library. Of course, No dependency on Microsoft Word.