C#/VB.NET: Convert OpenXML to Word or Word to OpenXML

2022-06-29 06:36:00 Written by  support iceblue
Rate this item
(0 votes)

OpenXML is an XML-based file format for MS Office documents. OpenXML is popular among developers as it allows creating and editing Office documents, such Word documents, with no need for MS Office. But when presented to ordinary users, OpenXML files usually need to be converted to Word documents to facilitate reading and editing. In this article, you can learn how to convert XML files to Word documents or Word documents to XML files with the help of Spire.Doc for .NET.

Install Spire.Doc for .NET

To begin with, you need to add the DLL files included in the Spire.Doc for .NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.Doc

Convert an OpenXML File to a Word Document

The detailed steps of the conversion are as follows:

  • Create an object of Document class.
  • Load an OpenXML file from disk using Document.LoadFromFile() method.
  • Convert the OpenXML file to a Word document and save it using Document.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Doc;
using System;

namespace DocExample
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Create a Document class instance
            Document document = new Document();

            //Load an OpenXML file from disk
            document.LoadFromFile(@"C:\Samples\Sample.xml", FileFormat.Xml);

            //Convert the OpenXML file to a Word document and save it
            document.SaveToFile("OpenXMLToWord.docx", FileFormat.Docx2013);
        }
    }
}

C#/VB.NET: Convert OpenXML to Word or Word to OpenXML

Convert a Word Document to an OpenXML File

The detailed steps of the conversion are as follows:

  • Create an object of Document class.
  • Load a Word document from disk using Document.LoadFromFile() method.
  • Convert the Word document to an OpenXML file and save it using Document.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Doc;
using System;

namespace DocExample
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Create a Document class instance
            Document document = new Document();

            //Load a Word document from disk
            document.LoadFromFile(@"C:\Samples\Sample.docx");

            //Convert the Word document to an OpenXML file and save it
            //Change WordXML to WordML to convert to ML file
            document.SaveToFile("WordToOpenXMl.xml", FileFormat.WordXml);
        }
    }
}

C#/VB.NET: Convert OpenXML to Word or Word to OpenXML

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

Additional Info

  • tutorial_title:
Last modified on Wednesday, 31 May 2023 08:47