首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >html-docx-js包产生无法读取的内容

html-docx-js包产生无法读取的内容
EN

Stack Overflow用户
提问于 2020-09-01 03:37:12
回答 1查看 113关注 0票数 0

最近有没有人能让html-docx-js运行起来?

我试过了:

代码语言:javascript
复制
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")

其中htmlPreview只是一个有效的HTML内容字符串。

然而,当我试图在Word中打开example2.docx时,我得到了这个错误:

"Word发现无法读取的内容“

当我在一个基本的文本编辑器中打开example2.docx时,我得到的是:

代码语言:javascript
复制
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

后面跟着我的输入字符串。

EN

回答 1

Stack Overflow用户

发布于 2020-12-10 12:09:56

html- Docx -js使用"altChunk“标记将原始的HTML文档嵌入到Docx文件中。

不幸的是,这在MacOS或Google Drive上不受支持,这就是为什么你看到的是一个空白文档。在Windows上的Word中打开它(甚至在Office365上在线打开它),它才能工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63677132

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档