Microsoft Word documents are available in two formats, DOC and DOCX. DOC is an older format, and DOCX is its successor. You can convert DOCX files to DOC format and vice-versa. In this article, you will learn how to convert a DOCX file to DOC format and a DOC file to DOCX format. You will also see how to perform these conversions in bulk. To explore these scenarios in detail, please see the following sections:
- C++ API for Converting DOCX to DOC and DOC to DOCX Format
- Converting DOCX File to DOC Format using C++
- Batch Convert DOCX Files to DOC Format using C++
- Convert DOC File to DOCX Format using C++
- Batch Convert DOC Files to DOCX Format using C++
C++ API for Converting DOCX to DOC and DOC to DOCX Format
Aspose.Words for C++ is a native C++ library that allows you to create, read, and modify Microsoft Word documents. Furthermore, it also supports converting DOCX files to DOC format and DOC files to DOCX format. You can either install the API through NuGet or download it directly from the Downloads section.
PM> Install-Package Aspose.Words.Cpp
Converting DOCX File to DOC Format using C++
You can convert a DOCX file to DOC format by following the steps given below.
- Create an instance of the LoadOptions class.
- Set the load format as DOCX using LoadOptions->set_LoadFormat(Aspose::Words::LoadFormat value) method.
- Load the source DOCX file using the Document class.
- Save the converted DOC file using Document->Save(System::String fileName, Aspose::Words::SaveFormat saveFormat) method.
The following sample code shows how to convert a DOCX file to a DOC file using C++.
Batch Convert DOCX Files to DOC Format using C++
If you have hundreds of DOCX files that you need to convert to DOC format, you can easily convert them by executing the program once. In this example, we will use the boost library to iterate through the files in the directory. The following are the steps to batch convert DOCX files to DOC format.
- Iterate through the files in the directory.
- Create an instance of the LoadOptions class.
- Set the load format as DOCX using LoadOptions->set_LoadFormat(Aspose::Words::LoadFormat value) method.
- Load the DOCX files using the Document class.
- Change the extension to DOC in the filename.
- Save the converted DOC file using the Document->Save(System::String fileName, Aspose::Words::SaveFormat saveFormat) method.
The following sample code demonstrates how to convert DOCX files to DOC format in bulk using C++.
Convert DOC File to DOCX Format using C++
The following are the steps to convert a DOC file to a DOCX file.
- Create an instance of the LoadOptions class.
- Set the load format as DOC using LoadOptions->set_LoadFormat(Aspose::Words::LoadFormat value) method.
- Load the source DOC file using the Document class.
- Save the converted DOCX file using Document->Save(System::String fileName, Aspose::Words::SaveFormat saveFormat) method.
The following sample code shows how to convert a DOC file to a DOCX file using C++.
Batch Convert DOC Files to DOCX Format using C++
In order to convert DOC files to DOCX format in bulk, use the steps given below.
- Iterate through the files in the directory.
- Create an instance of the LoadOptions class.
- Set the load format as DOC using LoadOptions->set_LoadFormat(Aspose::Words::LoadFormat value) method.
- Load the DOC files using the Document class.
- Change the extension to DOCX in the filename.
- Save the converted DOCX file using the Document->Save(System::String fileName, Aspose::Words::SaveFormat saveFormat) method.
The following sample code demonstrates how to convert DOC files to DOCX format in bulk using C++.
Get a Free License
You can try the API without evaluation limitations by requesting a free temporary license.
Conclusion
In this article, you have learned how to convert a DOCX file to DOC format and a DOC file to DOCX format using C++. Furthermore, you have seen how to perform these conversions in bulk using the boost library. Aspose.Words for C++ provides a bunch of additional features for automating your Word-related tasks. You can explore the API in detail by visiting the official documentation. In case of any questions, please feel free to reach us on our free support forum.