Bạn có thể chuyển đổi định dạng WORD sang JSON trong Ứng dụng Android của mình qua Aspose.Total for Android via Java . Bằng cách sử dụng API chuyển đổi và thao tác tài liệu Aspose.Words for Android via Java , bạn có thể xuất WORD sang HTML. Sau đó, bằng cách sử dụng Aspose.Cells for Android via Java , bạn có thể chuyển đổi HTML sang JSON.
Chuyển đổi định dạng WORD sang JSON trong Android
- Mở tệp WORD bằng lớp Wordument
- Chuyển đổi WORD sang HTML bằng cách sử dụng [Save]( https://reference.aspose.com/words/java/com.aspose.words/Wordument#save(java.lang.String , com.aspose.words.SaveOptions) ) phương pháp
- Tải tài liệu HTML bằng cách sử dụng lớp Workbook
- Lưu tài liệu sang định dạng JSON bằng cách sử dụng Save
Yêu cầu chuyển đổi
Bạn có thể dễ dàng sử dụng Aspose.Total for Android via Java trực tiếp từ Maven và cài đặt thư viện trong ứng dụng của bạn.
Ngoài ra, bạn có thể tải tệp ZIP từ download .
// 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); |
Chuyển đổi WORD được bảo vệ sang định dạng JSON trong Android qua Java
Sử dụng API, bạn cũng có thể mở tài liệu được bảo vệ bằng mật khẩu. Nếu tài liệu WORD đầu vào của bạn được bảo vệ bằng mật khẩu, bạn không thể chuyển đổi nó sang định dạng JSON mà không sử dụng mật khẩu. API cho phép bạn mở tài liệu được mã hóa bằng cách chuyển mật khẩu chính xác vào đối tượng LoadOptions. Ví dụ mã sau đây cho thấy cách mở một tài liệu được mã hóa bằng mật khẩu.
// 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); |
Chuyển đổi WORD sang JSON trong Range trong Android qua Java
Trong khi chuyển đổi WORD sang JSON, bạn cũng có thể đặt dải ô thành định dạng JSON đầu ra của mình. Để thiết lập phạm vi, bạn có thể mở HTML đã chuyển đổi bằng cách sử dụng lớp Workbook, tạo Phạm vi dữ liệu được xuất bằng phương thức Cells.createRange, gọi phương thức JsonUtility.exportRangeToJson với các tham chiếu của Range & ExportRangeToJsonOptions và ghi dữ liệu chuỗi JSON vào tệp qua Phương thức BufferedWriter.write.
// 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(); |