แปลง DOCM เป็นรูปแบบ JSON ผ่าน Java

บน Premise Java API เพื่อแปลง DOCM เป็น JSON โดยไม่ต้องใช้ Microsoft® Word หรือ Microsoft® Excel

 

การแปลงรูปแบบ DOCM เป็นรูปแบบ JSON ผ่าน Aspose.Total for Java เป็นกระบวนการสองขั้นตอนง่ายๆ เมื่อใช้ API การจัดการเอกสารและการแปลงที่มีคุณลักษณะหลากหลาย Aspose.Words for Java คุณจะส่งออก DOCM เป็น HTML ได้ หลังจากนั้น เมื่อใช้ Aspose.Cells for Java คุณจะแปลง HTML เป็น JSON ได้

แปลง DOCM เป็นรูปแบบ JSON ผ่าน Java

  1. เปิดไฟล์ DOCM โดยใช้คลาส Document
  2. แปลง DOCM เป็น HTML โดยใช้ บันทึก กระบวนการ
  3. โหลดเอกสาร HTML โดยใช้คลาส Workbook
  4. บันทึกเอกสารในรูปแบบ JSON โดยใช้ บันทึก วิธีการ

ข้อกำหนดการแปลง

คุณสามารถใช้ Aspose.Total สำหรับ Java ได้โดยตรงจากโปรเจ็กต์ที่ใช้ Maven และรวมไลบรารี่ไว้ใน pom.xml ของคุณ

หรือคุณสามารถรับไฟล์ 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);

ข้อกำหนดการแปลง

คุณยังสามารถเปิดเอกสารที่มีการป้องกันด้วยรหัสผ่านได้โดยใช้ API หากเอกสาร DOCM ที่คุณป้อนมีการป้องกันด้วยรหัสผ่าน คุณจะไม่สามารถแปลงเป็นรูปแบบ 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);

แปลง DOCM ที่ได้รับการป้องกันเป็นรูปแบบ JSON ผ่าน Java

ขณะที่คุณกำลังแปลง DOCM เป็น 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();

สำรวจ DOCM ตัวเลือกการแปลงด้วย Java

แปลง DOCM S TO EXCEL (รูปแบบไฟล์สเปรดชีต)