look_word.js 799 B

1234567891011121314151617181920212223242526272829
  1. //引入file-saver
  2. import saveAs from "file-saver/dist/FileSaver";
  3. //引入htmlDocx
  4. import htmlDocx from "html-docx-js/dist/html-docx";
  5. export const lookWord = (title, id, style, FX = false) => {
  6. let dom = document.querySelector(id);
  7. let str = dom.innerHTML;
  8. let orientation = FX;
  9. var orientations = ""
  10. if (orientation === true) {
  11. orientations = "landscape"
  12. } else {
  13. orientations = ""
  14. }
  15. let htmlStr = `
  16. <!DOCTYPE html>
  17. <html lang="en">
  18. <style>
  19. ${style}
  20. </style>
  21. <body style="font-family:方正仿宋_GBK;mso-ascii-font-family:'Times New Roman'">
  22. ${str}
  23. </body>
  24. </html>`;
  25. saveAs(
  26. htmlDocx.asBlob(htmlStr, { orientation: orientations }), title
  27. );
  28. }