简体   繁体   English

html-docx-js package 产生不可读的内容

[英]html-docx-js package produces unreadable content

Has anyone been able to get html-docx-js to work recently?最近有没有人能够让 html-docx-js 工作?

I've tried this:我试过这个:

var newHTML =
      "<!DOCTYPE html><html><head lang='en'><meta charset='UTF-8'><title>Report</title></head><body>" +
      htmlPreview +
      "</body></html>"
    const newBlob = htmldocx.asBlob(newHTML)
    saveAs(newBlob, "example2.docx")

where htmlPreview is just a valid string of HTML stuff.其中 htmlPreview 只是 HTML 内容的有效字符串。

However when I try to open example2.docx in Word I get this error:但是,当我尝试在 Word 中打开 example2.docx 时,出现此错误:

"Word found unreadable content" “Word 发现不可读的内容”

When I open example2.docx in a basic text editor this is what I get:当我在基本文本编辑器中打开 example2.docx 时,这就是我得到的:

PK
      yQ               _rels/PK
      yQ               word/PK
      yQ"?!à       word/document.xml<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document
  xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
  xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"
  xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
  xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
  xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
  xmlns:ns6="http://schemas.openxmlformats.org/schemaLibrary/2006/main"
  xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart"
  xmlns:ns8="http://schemas.openxmlformats.org/drawingml/2006/chartDrawing"
  xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram"
  xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"
  xmlns:ns11="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"
  xmlns:dsp="http://schemas.microsoft.com/office/drawing/2008/diagram"
  xmlns:ns13="urn:schemas-microsoft-com:office:excel"
  xmlns:o="urn:schemas-microsoft-com:office:office"
  xmlns:v="urn:schemas-microsoft-com:vml"
  xmlns:w10="urn:schemas-microsoft-com:office:word"
  xmlns:ns17="urn:schemas-microsoft-com:office:powerpoint"
  xmlns:odx="http://opendope.org/xpaths"
  xmlns:odc="http://opendope.org/conditions"
  xmlns:odq="http://opendope.org/questions"
  xmlns:odi="http://opendope.org/components"
  xmlns:odgm="http://opendope.org/SmartArt/DataHierarchy"
  xmlns:ns24="http://schemas.openxmlformats.org/officeDocument/2006/bibliography"
  xmlns:ns25="http://schemas.openxmlformats.org/drawingml/2006/compatibility"
  xmlns:ns26="http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas">
  <w:body>
    <w:altChunk r:id="htmlChunk" />
    <w:sectPr>
      <w:pgSz w:w="12240" w:h="15840" w:orient="portrait" />
      <w:pgMar w:top="1440"
               w:right="1440"
               w:bottom="1440"
               w:left="1440"
               w:header="720"
               w:footer="720"
               w:gutter="0"/>
    </w:sectPr>
  </w:body>
</w:document>
PK
      yQ½`'N 'N    word/afchunk.mhtMIME-Version: 1.0
Content-Type: multipart/related;
    type="text/html";
    boundary="----=mhtDocumentPart"


------=mhtDocumentPart
Content-Type: text/html;
    charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Location: file:///C:/fake/document.html

followed by my input string.其次是我的输入字符串。

html-docx-js uses "altChunk" markup to embed a raw HTML document within a Docx file. html-docx-js 使用“altChunk”标记在 Docx 文件中嵌入原始 HTML 文档。

Unfortunately, this is not supported on MacOS or Google Drive, which is why you're seeing a blank document instead.不幸的是,这在 MacOS 或 Google Drive 上不受支持,这就是为什么您看到的是空白文档。 Open it in Word on Windows (or even online at Office365) for it to work.在 Windows(或什至在 Office365 在线)上的 Word 中打开它以使其工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM