您可以通过 Aspose.Total for Android via Java 分两步在 Android 应用程序中轻松地将 POWERPOINT 文件转换为 JSON。第一步,您可以使用 Aspose.Slides for Android via Java 将 POWERPOINT 文件导出为 HTML。其次,通过使用 Aspose.Cells for Android via Java ,您可以将 HTML 转换为 JSON。
如何在 Android 中将 POWERPOINT 转换为 JSON
- 使用 Presentation 类打开 POWERPOINT 文件
- 使用 save 将 POWERPOINT 转换为 HTML。ISaveOptions-) 方法
- 使用 Workbook 类加载 HTML 文档
- 使用 save 将文档保存为 JSON 格式
// 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); |
在 Android 中通过 Java 将 Protected POWERPOINT 转换为 JSON
使用 API,您还可以打开受密码保护的文档。如果您输入的 POWERPOINT 文档受密码保护,则您无法在不使用密码的情况下将其转换为 JSON。 API 允许您通过在 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); |
在 Android 中将 POWERPOINT 文件转换为带有水印的 JSON
在将 POWERPOINT 文件转换为 JSON 时,您还可以在输出的 JSON 文件格式中添加水印。为了添加水印,创建一个新的工作簿来打开转换后的 HTML 文件。通过其索引选择 Worksheet,创建一个 Shape 并使用其 addTextEffect 函数,设置颜色、透明度等。之后,您可以将 HTML 文档保存为带水印的 JSON。
// 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(); |