简体   繁体   English

将 docx 文件中的文本输出到文本区域

[英]Output the text from a docx file to a text area

I want to take the text from a docx file and and put it as the value of a textarea when a user clicks a button?我想从 docx 文件中获取文本,并在用户单击按钮时将其作为 textarea 的值? I know how to create a button, change value of the textarea and so on, what I can't figure out is how to take the text from the docx file, with formatting elements if possible.我知道如何创建一个按钮,更改 textarea 的值等等,我不知道如何从 docx 文件中获取文本,如果可能的话,带有格式元素。 And I need to mention that I GET the docx file from an external server.我需要提到的是我从外部服务器获取 docx 文件。

Thanks!谢谢!

Here is what you can do using : Docxtemplater以下是您可以使用的方法: Docxtemplater

Things to remember:要记住的事情:

If you are directly downloading the file from build and not from cdn as used in this script, then you will have to create new Docxtemplater() instead of new window.docxtemplater() ;如果您直接从build下载文件而不是从本脚本中使用的 cdn 下载文件,那么您将必须创建new Docxtemplater()而不是new window.docxtemplater()

 var openFile = function(event) { var input = event.target; var reader = new FileReader(); reader.onload = function() { var zip = new JSZip(reader.result); var doc = new window.docxtemplater().loadZip(zip); var text = doc.getFullText(); var node = document.getElementById('output'); node.innerText = text; }; reader.readAsBinaryString(input.files[0]); };
 <script src="https://cdnjs.cloudflare.com/ajax/libs/docxtemplater/3.1.9/docxtemplater.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/2.6.1/jszip.js"></script> <input type='file' onchange='openFile(event)'> <br> <div id='output'>...</div>

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

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