La conversione del formato DOT in formato JSON tramite Aspose.Total for Java è un semplice processo in due fasi. Utilizzando l’API di conversione e manipolazione dei Documenti ricca di funzionalità Aspose.Words per Java , puoi esportare DOT in HTML. Successivamente, utilizzando Aspose.Cells for Java , puoi convertire HTML in JSON.
Converti DOT in formato JSON tramite Java
Requisiti di conversione
Puoi facilmente utilizzare Aspose.Total per Java direttamente da un progetto basato su Maven e includi le librerie nel tuo pom.xml.
In alternativa, puoi ottenere un file ZIP da 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); |
Requisiti di conversione
Utilizzando l’API, puoi anche aprire il dotumento protetto da password. Se il dotumento DOT di input è protetto da password, non è possibile convertirlo in formato JSON senza utilizzare la password. L’API consente di aprire il dotumento crittografato passando la password corretta in un oggetto LoadOptions. L’esempio di codice seguente mostra come provare ad aprire un dotumento crittografato con una 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); |
Converti DOT protetto in formato JSON tramite Java
Durante la conversione di DOT in JSON, puoi anche impostare l’intervallo sul formato JSON di output. Per impostare l’intervallo, è possibile aprire l’HTML convertito utilizzando la classe Workbook, creare un intervallo di dati da esportare utilizzando il metodo Cells.createRange, chiamare il metodo JsonUtility.exportRangeToJson con i riferimenti di Range & ExportRangeToJsonOptions e scrivere i dati JSON della stringa su file tramite BufferedWriter.write metodo.
// 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(); |