Using Aspose.Total for Java, converting DOTX to JSON format is a straightforward two-step process. Aspose.Total for Java is a comprehensive suite of feature-rich document manipulation and conversion APIs that enable developers to quickly and easily convert documents from one format to another.
The first step is to export DOTX to HTML using Aspose.Words for Java. Aspose.Words for Java is a powerful document manipulation API that enables developers to create, edit, convert, and print documents in various formats, including DOTX. It provides a wide range of features, such as document creation, manipulation, and conversion, as well as support for a variety of document formats. With Aspose.Words for Java, developers can easily export DOTX to HTML.
The second step is to convert HTML to JSON using Aspose.Cells for Java. Aspose.Cells for Java is a powerful spreadsheet manipulation API that enables developers to create, edit, and convert spreadsheets in various formats, including HTML. It provides a wide range of features, such as spreadsheet creation, manipulation, and conversion, as well as support for a variety of spreadsheet formats. With Aspose.Cells for Java, developers can easily convert HTML to JSON.
By using Aspose.Total for Java, developers can quickly and easily convert DOTX to JSON format in just two steps. Aspose.Words for Java enables developers to export DOTX to HTML, and Aspose.Cells for Java enables developers to convert HTML to JSON. With Aspose.Total for Java, developers can easily manipulate and convert documents from one format to another.
Convert DOTX to JSON Format via Java
Conversion Requirements
You can easily use Aspose.Total for Java directly from a Maven based project and include libraries in your pom.xml.
Alternatively, you can get a ZIP file from downloads .
// supports DOC, DOT, DOCX, DOCM, DOTX, DOTM, RTF, WordML, MOBI, ODT, and OTT input file formats | |
// load DOCX with an instance of Document | |
Document document = new Document("template.docx"); | |
// call Save method while passing SaveFormat.HTML | |
document.save("html_output.html",SaveFormat.HTML); | |
// load the HTML file in an instance of Workbook | |
Workbook book = new Workbook("html_output.html"); | |
// save HTML as JSON | |
book.save("output.json", SaveFormat.JSON); |
Convert Protected DOTX to JSON Format via Java
Using the API, you can also open the password-protected document. If your input DOTX document is password protected, you cannot convert it to JSON format without using the password. The API allows you to open the encrypted document by passing the correct password in a LoadOptions object. The following code example shows how to try opening an encrypted document with a password:
// supports DOC, DOT, DOCX, DOCM, DOTX, and DOTM file formats | |
// load DOCX with an instance of Document | |
Document document = new Document("template.docx", new LoadOptions("MyPassword")); | |
// call Save method while passing SaveFormat.HTML | |
document.save("html_output.html",SaveFormat.HTML); | |
// load the HTML file in an instance of Workbook | |
Workbook book = new Workbook("html_output.html"); | |
// save HTML as JSON | |
book.save("output.json", SaveFormat.JSON); |
Convert DOTX to JSON in Range via Java
While you are converting DOTX to JSON, you can also set range to your output JSON format. In order to set the range, you can open the converted HTML using Workbook class, create a Range of data to be exported using Cells.createRange method, call JsonUtility.exportRangeToJson method with references of Range & ExportRangeToJsonOptions and write string JSON data to file via BufferedWriter.write method.
// supports DOC, DOT, DOCX, DOCM, DOTX, DOTM, RTF, WordML, MOBI, ODT, and OTT input file formats | |
// load DOCX with an instance of Document | |
Document document = new Document("template.docx"); | |
// call Save method while passing SaveFormat.HTML | |
document.save("html_output.html",SaveFormat.HTML); | |
// load the HTML file in an instance of Workbook | |
Workbook book = new Workbook("html_output.html"); | |
// access CellsCollection of the worksheet containing data to be converted | |
Cells cells = workbook.getWorksheets().get(0).getCells(); | |
// create & set ExportRangeToJsonOptions for advanced options | |
ExportRangeToJsonOptions exportOptions = new ExportRangeToJsonOptions(); | |
// create a range of cells containing data to be exported | |
Range range = cells.createRange(0, 0, cells.getLastCell().getRow() + 1, cells.getLastCell().getColumn() + 1); | |
// export range as JSON data | |
String jsonData = JsonUtility.exportRangeToJson(range, exportOptions); | |
// write data to disc in JSON format | |
BufferedWriter writer = new BufferedWriter(new FileWriter("output.json")); | |
writer.write(jsonData); | |
writer.close(); |