Puoi convertire WORD in formato JSON nelle tue applicazioni Android tramite Aspose.Total for Android via Java . Utilizzando l’API di conversione e manipolazione dei wordumenti Aspose.Words for Android via Java , puoi esportare WORD in HTML. Successivamente, utilizzando Aspose.Cells for Android via Java , puoi convertire HTML in JSON.
Converti WORD in formato JSON in Android
Requisiti di conversione
Puoi facilmente utilizzare Aspose.Total for Android via Java direttamente da Maven e installa le librerie nella tua app.
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); |
Converti il formato WORD protetto in formato JSON in Android tramite Java
Utilizzando l’API, puoi anche aprire il wordumento protetto da password. Se il wordumento WORD di input è protetto da password, non è possibile convertirlo in formato JSON senza utilizzare la password. L’API consente di aprire il wordumento crittografato passando la password corretta in un oggetto LoadOptions. L’esempio di codice seguente mostra come aprire un wordumento 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 WORD in JSON nell'intervallo in Android tramite Java
Durante la conversione di WORD 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(); |