คุณสามารถแปลง WORD เป็นรูปแบบ JSON ในแอปพลิเคชัน Android ของคุณผ่าน Aspose.Total for Android via Java ด้วยการใช้การจัดการเอกสารและการแปลง API Aspose.Words for Android via Java คุณสามารถส่งออก WORD เป็น HTML ได้ หลังจากนั้น ด้วยการใช้ Aspose.Cells for Android via Java คุณจะสามารถแปลง HTML เป็น JSON ได้
แปลง WORD เป็นรูปแบบ JSON ใน Android
ข้อกำหนดการแปลง
คุณสามารถใช้ Aspose.Total for Android via Java ได้โดยตรงจาก Maven และ ติดตั้งไลบรารีในแอปของคุณ
หรือคุณสามารถรับไฟล์ ZIP จาก ดาวน์โหลด
// 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); |
แปลง WORD ที่ได้รับการป้องกันเป็นรูปแบบ JSON ใน Android ผ่าน Java
คุณยังสามารถเปิดเอกสารที่ป้องกันด้วยรหัสผ่านโดยใช้ API ได้อีกด้วย หากเอกสาร WORD ที่คุณป้อนมีการป้องกันด้วยรหัสผ่าน คุณจะไม่สามารถแปลงเป็นรูปแบบ JSON ได้โดยไม่ต้องใช้รหัสผ่าน API อนุญาตให้คุณเปิดเอกสารที่เข้ารหัสโดยส่งรหัสผ่านที่ถูกต้องในออบเจกต์ LoadOptions ตัวอย่างโค้ดต่อไปนี้แสดงวิธีการเปิดเอกสารที่เข้ารหัสด้วยรหัสผ่าน
// 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); |
แปลง WORD เป็น JSON ในช่วงใน Android ผ่าน Java
ขณะที่คุณกำลังแปลง WORD เป็น JSON คุณยังสามารถตั้งค่าช่วงเป็นรูปแบบ JSON เอาต์พุตของคุณได้ ในการตั้งค่าช่วง คุณสามารถเปิด HTML ที่แปลงแล้วโดยใช้คลาสเวิร์กบุ๊ก สร้างช่วงของข้อมูลที่จะส่งออกโดยใช้เมธอด Cells.createRange เรียกเมธอด JsonUtility.exportRangeToJson พร้อมการอ้างอิงของ Range & ExportRangeToJsonOptions และเขียนสตริงข้อมูล JSON ไปยังไฟล์ผ่าน วิธีการ 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(); |