Why to Convert
Converting documents from one format to another is a common requirement for many applications. For example, converting a DOC file to JSON format can be useful for web applications that need to store and display data in a structured format. JSON is a popular data format that is used for storing and exchanging data between different applications.
How Aspose.Total Helps for DOC to JSON Conversion
Aspose.Total for C++ is a suite of APIs that can be used to convert documents from one format to another. It includes Aspose.Words for C++, which can be used to export DOC files to HTML. Aspose.Cells for C++ can then be used to convert the HTML to JSON format. This makes it easy to convert DOC files to JSON format within C++ applications.
Convert DOC to JSON Format via C++
Get Started with C++ File Automation APIs
Install via Package Manager Console of Visual Studio with Install-Package Aspose.Total.Cpp
.
Alternatively, get the offline MSI installer or DLLs in a ZIP file from downloads .
// supports DOC, DOT, DOCX, DOCM, DOTX, DOTM, RTF, WordML, MOBI, ODT, and OTT file formats | |
// load DOCX as input file format with an instance of Document class | |
auto doc = MakeObject<Document>(u"Input.docx"); | |
// save document in HTML format | |
doc->Save(u"Output.html"); | |
// Load the HTML. | |
intrusive_ptr<Aspose::Cells::IWorkbook> wkb = Factory::CreateIWorkbook(u"Output.html"); | |
// Save in JSON format. | |
wkb->Save(u"Output.json", SaveFormat_Json); |
Convert Protected DOC to JSON Format via C++
Using the API, you can also open the password-protected document. If your input DOC document is password protected, you cannot convert it to JSON format without using the password. To do this, use a special constructor overload, which accepts a LoadOptions object. This object contains the Password property, which specifies the password string.
// supports DOC, DOT, DOCX, DOCM, DOTX, DOTM, RTF, WordML, MOBI, ODT, and OTT file formats | |
// Loads encrypted document. | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(u"LoadEncrypted.docx", System::MakeObject<LoadOptions>(u"aspose")); | |
// save document in HTML format | |
doc->Save(u"Output.html"); | |
// Load the HTML. | |
intrusive_ptr<Aspose::Cells::IWorkbook> wkb = Factory::CreateIWorkbook(u"Output.html"); | |
// Save in JSON format. | |
wkb->Save(u"Output.json", SaveFormat_Json); |