La conversione del formato POTX in formato JSON tramite Aspose.Total for Java è un semplice processo in due fasi. Nel primo passaggio puoi esportare POTX in HTML utilizzando Aspose.Slides for Java . In secondo luogo, utilizzando Aspose.Cells for Java , puoi convertire HTML in JSON.
Converti POTX in formato JSON tramite Java
- Aprire il file POTX utilizzando la classe Presentazione
- Converti POTX in HTML utilizzando [save]( https://apiference.aspose.com/slides/java/com.aspose.slides/Presentation#save-java.lang.String-int-com.aspose.slides . ISaveOptions-) metodo
- Caricare il documento HTML utilizzando la classe Workbook
- Salvare il documento in formato JSON utilizzando save .
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 PPT, POT, PPS, POTX, PPSX, PPTM, PPSM, POTM, ODP, and OTP input file formats | |
// instantiate a Presentation object that represents a PPT file | |
Presentation presentation = new Presentation("template.ppt"); | |
// save the presentation as HTML | |
presentation.save("output.html", SaveFormat.Html); | |
// load the HTML file in an instance of Workbook | |
Workbook book = new Workbook("output.html"); | |
// save HTML as JSON | |
book.save("output.json", SaveFormat.JSON); |
Requisiti di conversione
Utilizzando l’API, puoi anche aprire il documento protetto da password. Se il documento POTX di input è protetto da password, non è possibile convertirlo in formato JSON senza utilizzare la password. L’API consente di aprire il documento crittografato passando la password corretta in un oggetto LoadOptions.
// initialize load options | |
LoadOptions loadOptions = new LoadOptions(); | |
// set password | |
loadOptions.setPassword("123123"); | |
// supports PPT, POT, PPS, POTX, PPSX, PPTM, PPSM, POTM, ODP, and OTP input file formats | |
Presentation presentation = new Presentation("pres.pptx", loadOptions); | |
// save the presentation as HTML | |
presentation.save("output.html", SaveFormat.Html); | |
// load the HTML file in an instance of Workbook | |
Workbook book = new Workbook("output.html"); | |
// save HTML as JSON | |
book.save("output.json", SaveFormat.JSON); |
Converti POTX protetto in formato JSON tramite Java
Durante la conversione da POTX a 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 PPT, POT, PPS, POTX, PPSX, PPTM, PPSM, POTM, ODP, and OTP input file formats | |
// instantiate a Presentation object that represents a PPT file | |
Presentation presentation = new Presentation("template.ppt"); | |
// save the presentation as HTML | |
presentation.save("output.html", SaveFormat.Html); | |
// load the HTML file in an instance of Workbook | |
Workbook book = new Workbook("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(); |