docx2html.html 885 B

1234567891011121314151617181920212223242526272829303132
  1. <!DOCTYPE html><html>
  2. <title>docx2html</title>
  3. <head>
  4. <script src="https://fastly.jsdelivr.net/npm/mammoth@1.4.8/mammoth.browser.min.js"></script>
  5. </head>
  6. <body>
  7. <div>
  8. <center>
  9. <h2>select a docx to convert to html</h2>
  10. <input type="file" onchange="convert(this)"/>
  11. </center>
  12. <div id="container"></div>
  13. </div>
  14. <script>
  15. var container = document.querySelector("#container");
  16. function convert(input){
  17. var files = input.files||[];
  18. if (!files.length) return;
  19. var file = files[0];
  20. var reader = new FileReader();
  21. reader.onloadend = function(event) {
  22. var arrayBuffer = reader.result;
  23. mammoth.convertToHtml({arrayBuffer: arrayBuffer}).then(function (resultObject) {
  24. container.innerHTML = resultObject.value
  25. });
  26. }
  27. reader.readAsArrayBuffer(file);
  28. }
  29. </script>
  30. </body>
  31. </html>