Convert ODT to DOC or DOCX and Vice Versa in C#, VB.NET

2018-01-30 07:18:37 Written by  support iceblue
Rate this item
(0 votes)

A file with the .ODT file extension is an OpenDocument Text document file. These files are most often created by the free OpenOffice Writer word processor program. ODT files are similar to the popular DOCX file format used with Microsoft Word. Both of the two file types can hold things like text, images, objects, and styles.

However, when you open an ODT document in Microsoft Word, the formatting of the ODT document may differ as a result of the two programs not sharing the same features. When converting ODT to DOCX or vice versa, the data and content will be converted successfully, but may not including the original formatting.

Following code snippets introduce how to convert ODT to DOC or DOCX and vice versa using Spire.Doc.

ODT to DOCX

To convert ODT to DOC, change the file extension and file format to .Doc in SaveToFile method.

[C#]
using Spire.Doc;

namespace ODTtoDOCX
{
    class Program
    {
        static void Main(string[] args)
        {
            Document doc = new Document();
            doc.LoadFromFile("SampleODTFile.odt");
            doc.SaveToFile("output.docx", FileFormat.Docx)

        }

 
    }
}
[VB.NET]
Imports Spire.Doc

Namespace ODTtoDOCX
	Class Program
		Private Shared Sub Main(args As String())
			Dim doc As New Document()
			doc.LoadFromFile("SampleODTFile.odt")
			doc.SaveToFile("output.docx", FileFormat.Docx)

		End Sub
	End Class
End Namespace

DOCX to ODT

To convert Doc to ODT, load a .Doc file format document when loading the source file.

[C#]
using Spire.Doc;
namespace DOCXtoODT
{
    class Program
    {
        static void Main(string[] args)
        {
            Document doc = new Document();
            doc.LoadFromFile("SampleODTFile.odt");
            doc.SaveToFile("output.docx", FileFormat.Docx);

        } 
    }
}
[VB.NET]
Imports Spire.Doc
Namespace DOCXtoODT
	Class Program
		Private Shared Sub Main(args As String())
			Dim doc As New Document()
			doc.LoadFromFile("SampleODTFile.odt")
			doc.SaveToFile("output.docx", FileFormat.Docx)

		End Sub
	End Class
End Namespace

Additional Info

  • tutorial_title:
Last modified on Friday, 03 September 2021 03:23