Aspose.Total for Java 를 통해 POT를 JSON 형식으로 변환하는 것은 간단한 2단계 프로세스입니다. 첫 번째 단계에서는 Aspose.Slides for Java 를 사용하여 POT를 HTML로 내보낼 수 있습니다. 둘째, Aspose.Cells for Java 를 사용하여 HTML을 JSON으로 변환할 수 있습니다.
Java를 통해 POT를 JSON 형식으로 변환
- Presentation 클래스를 사용하여 POT 파일을 엽니다.
- save 을 사용하여 POT를 HTML로 변환합니다. ISaveOptions-) 메서드
- Workbook 클래스를 사용하여 HTML 문서 로드
- save 을 사용하여 문서를 JSON 형식으로 저장합니다. SaveOptions)) 메서드
변환 요구 사항
Maven 기반 프로젝트에서 직접 Java용 Aspose.Total을 쉽게 사용할 수 있습니다. pom.xml에 라이브러리를 포함합니다.
또는 다운로드 에서 ZIP 파일을 받을 수 있습니다.
// 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); |
변환 요구 사항
API를 사용하여 암호로 보호된 문서를 열 수도 있습니다. 입력 POT 문서가 비밀번호로 보호되어 있는 경우 비밀번호를 사용하지 않고는 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); |
Java를 통해 보호된 POT를 JSON 형식으로 변환
POT를 JSON으로 변환하는 동안 범위를 출력 JSON 형식으로 설정할 수도 있습니다. 범위를 설정하려면 변환된 HTML을 Workbook 클래스를 사용하여 열고, Cells.createRange 메서드를 사용하여 내보낼 데이터 범위를 만들고, Range & ExportRangeToJsonOptions를 참조하여 JsonUtility.exportRangeToJson 메서드를 호출하고, 문자열 JSON 데이터를 파일에 씁니다. BufferedWriter.write 메서드.
// 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(); |