Product Family

Create DOCM Documents via C#

Native and high performance Microsoft Word DOCM files creation using server side .NET APIs.

Generating MS Word DOCM file dynamically within running application is easy. In order to create DOCM documents from scratch without requiring MS Office, we’ll use

Aspose.Words for .NET

API that offers different features for document creation, manipulation and conversion using .NET platform.

How to Create DOCM via C#

It is easy for the developers to creat, load, modify and convert DOCM files within running Word Automation applications for data processing in just a few lines of code.

  1. Include the namespace in your class file
  2. Create a Document class object.
  3. Create DocumentBuilder class object and initialize it with the Document object.
  4. Update elements using the DocumentBuilder object.
  5. Save the file using Save(.) method.

System Requirements

Just make sure that system have Microsoft Windows or a compatible OS with .NET Framework, .NET Core, Windows Azure, Mono or Xamarin Platforms as well as development environment like Microsoft Visual Studio.

  • Install from command line as nuget install Aspose.Words or via Package Manager Console of Visual Studio with Install-Package Aspose.Words.
  • Alternatively, get the offline MSI installer or all DLLs in a ZIP file from downloads

Following source code shows how to create a Word DOCM file using C#.

Document docm = new Document();
DocumentBuilder bldr = new DocumentBuilder(docm);

// Define relevant font formatting
Font fnt = bldr.Font;
fnt.Size = 32;
fnt.Bold = true;
fnt.Color = System.Drawing.Color.Black;
fnt.Name = "Arial";
fnt.Underline = Underline.Single;

// Insert text
bldr.Writeln("This is the first page.");

// Change formatting for next elements.
fnt.Underline = Underline.None;
fnt.Size = 10;
fnt.Color = System.Drawing.Color.Blue;

bldr.Writeln("This following is a table");
// Insert a table
Table table = bldr.StartTable();
// Insert a cell
// Use fixed column widths.
bldr.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
bldr.Write("row one cell one");
// Insert a cell
bldr.Write("row one cell two");
bldr.Write("row two cell one");
bldr.Write("row two cell two");

// Insert image
// Insert page break 
// Elements after page break will be inserted to next page.

// Save it to get the created one
A Document Processing Library to perform a wide range of document management and manipulation tasks including DOCM generation, editing, conversion, rendering and printing. .NET Word API supports all of word-processing formats as well as allows exporting or converting DOCM to PDF, HTML, fixed-layout and most commonly used image & multimedia formats.

DOCM What is DOCM File Format

DOCM files are Microsoft Word 2007 or higher generated documents with the ability to run macros. It is similar to DOCX file format but the ability to run macros makes it different from DOCX. Like DOCX, DOCM files can be store text, images, tables, shapes, charts and other contents.The capability to run macros make it easy to save time by executing the series of commands in the form of recorded actions for automatic completion of a task. DOCM files can be opened and edited in Microsoft Word 2007 and above.

Read More

Other Supported Document Generation

You can also create other Microsoft Words file formats including few listed below.

DOC (Microsoft Word Binary Format)
DOCX (Office 2007+ Word Document)
RTF (Rich Text Format)
DOT (Microsoft Word Template Files)
DOTX (Microsoft Word Template File )
DOTM (Microsoft Word 2007+ Template File)
DOCM (Microsoft Word 2007 Marco File)
ODT (OpenDocument Text File Format)