Word File Formats in Essential DocIO

16 Oct 20203 minutes to read

The Microsoft Word’s native file formats are DOCX, DOTX, DOCM, and DOTM. The Essential DocIO supports the following major native file formats.

  1. Word Open XML formats (2007 & later)
  2. Word Processing XML (.xml)

Word Open XML formats (2007 & later)

Office Open XML (OOXML or Microsoft Open XML (MOX)) is a zipped, new XML-based file format introduced by Microsoft in Office 2007 applications.The WordprocessingML is the markup language used by the Microsoft Office Word to store its DOCX documents.

DocIO supports the following WordprocessingML:

  • Microsoft Word 2007
  • Microsoft Word 2010
  • Microsoft Word 2013
  • Microsoft Word 2016
  • Microsoft Word 2019

The following code example explains how to create a new Word document with a few lines of code.

//Create an instance of the WordDocument Instance (Empty Word Document).
WordDocument document = new WordDocument();
//Add a section and a paragraph in the empty document.
document.ensureMinimal();
//Append text to the last paragraph of the document.
document.getLastParagraph().appendText("Hello World");
//Save and close the Word document.
document.save("Sample.docx");
document.close();

Templates

DOTX is a Word document template. The following code sample shows how to create the Word document template with a few lines of code.

//Create an instance of the WordDocument Instance (Empty Word Document).
WordDocument document = new WordDocument();
//Add a section and a paragraph in the empty document.
document.ensureMinimal();
//Append text to the last paragraph of the document.
document.getLastParagraph().appendText("Hello World");
//Save and close the Word document.
document.save("Sample.dotx");
document.close();

Macros

DOCM is a macro-enabled Word document. It is same as the DOCX document contains macros and scripts. The DocIO provides only preservation support for macros. The following code shows how to load and save a macro-enabled document using the DocIO library.

// Load the macro-enabled template.
WordDocument document = new WordDocument("Template.dotm");
// Get the table.
DataTableSupport table = getDataTable();
// Execute the Mail Mmrge with groups.
document.getMailMerge().executeGroup(table);
//Save and close the document.
document.save("Sample.docm", FormatType.Word2013Docm);
document.close();

Word Processing XML (.xml)

The XML format introduced in Microsoft Word 2003 was a simple, XML-based format called WordprocessingML or WordML.
The Essential DocIO supports converting the Word document into Word Processing XML document and vice versa.

NOTE

  1. Importing and exporting the Word Processing 2007 XML documents is supported.
  2. Exporting the Word Processing 2003 XML document is not supported. Whereas you can import the Word Processing 2003 XML documents and export it to the other supported file formats.
  3. The custom XML elements present in the Word Processing 2003 XML documents will be removed automatically while importing, like latest Microsoft Word. The custom XML element is a depreciated feature in latest Microsoft Word.

The following code example shows how to convert the Word document into Word Processing XML document.

//Load an existing Word document.
WordDocument document = new WordDocument("Sample.docx");
//Save the document as a Word Processing ML document.
document.save("WordToWordML.xml", FormatType.WordML);
//Close the document.
document.close();

The following code example shows how to convert the Word Processing XML document into Word document.

// Load an existing Word document. 
WordDocument document = new WordDocument("Template.xml");
//Save the Word Processing ML document as docx.
document.save("WordMLToWord.docx", FormatType.Docx);
//Close the document.
document.close();

Unsupported elements in Word to Word Processing XML conversion:

The following table contains a list of unsupported elements in the Word to Word Processing XML conversion.

Element Limitations or Unsupported elements
Custom Shapes

Not supported

Embedded fonts

Not supported

Equation

Not supported

SmartArt

Not supported

WordArt

Not supported

Form Fields Unparsed in Word Processing 2003 XML document
Ole Object Not supported