【问题标题】:How To Convert HTML Tags Into WordDoc Text Format? Using DOCX.js Library如何将 HTML 标签转换为 WordDoc 文本格式?使用 DOCX.js 库
【发布时间】:2021-11-04 11:10:14
【问题描述】:

我在将 HTML 文本转换为 word doc 支持格式时遇到问题,因此我可以使用 docx.js lib 生成 doc 文件。现在 HTML 标签显示为计划文本。

这是我正在使用的库:https://docx.js.org/

<p>
  <strong>voice:</strong> 
  During an address to Congress, George Washington said “If you can’t send money, send cigars.” [pause]  Or something like that.  [pause]  There’s no question that Washington was a wise man.  He knew that premium quality cigars are worth their weight in gold. And if he were alive today, he’d be running the country from the lounge at 
  <strong>No Name Cigar Company.</strong> 
  Where the conversation never comes to an end &#8211; and neither does their premier cigar selection. Mingle with legends &#8211; at 
  <strong>No Name Cigar Company.</strong>
</p> 
<p>&nbsp;</p> 
<p>Visit them online at <strong>NoNameWebsite.com</strong></p>`

【问题讨论】:

  • 阅读文档
  • 通过快速阅读文档,该库不是这样工作的。似乎没有办法以这种方式转换 HTML。

标签: javascript html docx


【解决方案1】:

您好,请使用googoose 这工作非常快,没有故障

这是完整的代码示例

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>              
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/aadel112/googoose@master/jquery.googoose.js"></script>

<script type="text/javascript">
$(document).ready(function() {
    var o = {
        filename: 'test.doc'
    };
    $(document).googoose(o);
});
</script>

</head>
<body>
The content that is rendered to a Word doc will need to be wrapped in a div with the classname googoose-wrapper, by default.
<div class="googoose-wrapper">  
<p><strong>voice:</strong> During an address to Congress, George Washington said “If you can’t send money, send cigars.” [pause]  Or something like that.  [pause]  There’s no question that Washington was a wise man.  He knew that premium quality cigars are worth their weight in gold. And if he were alive today, he’d be running the country from the lounge at <strong>No Name Cigar Company.</strong> Where the conversation never comes to an end &#8211; and neither does their premier cigar selection. Mingle with legends &#8211; at <strong>No Name Cigar Company.</strong></p> <p>&nbsp;</p> <p>Visit them online at <strong>NoNameWebsite.com</strong></p> 
</div>
</body>
</html>

【讨论】:

  • 嗨,阿西夫 - 感谢您的建议。我正在使用 googoose lib 生成一个 word Docx 文件。但我面临一个问题。当我在 word doc 中添加图像时。它没有显示,而是在 MS Word 中显示了一个交叉的图像图标。 (这只发生在只读模式下。)。但是在编辑文档时,图像会显示出来。你能告诉我在这个 googoose 库中的 word doc 中使用图像的正确方法是什么。谢谢!
  • 试试这个,将图像转换为base64并添加到您的HTML中,然后将其转换为word文件,如果这个想法不起作用,请告诉我。
  • 嗨,Asif 感谢您的建议,但我实际上用更可靠的库替换了库。 "PHPWord"
猜你喜欢
  • 2015-11-20
  • 2017-06-13
  • 2023-04-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-26
  • 1970-01-01
相关资源
最近更新 更多