JavaScript library to read doc and docx on client

久未见 提交于 2019-12-31 01:06:35

问题


I am searching for a JavaScript library, which can read .doc - and .docx - files. The focus is only on the text content. I am not interested in pictures, formulas or other special structures in MS-Word file.

It would be great if the library works with to JavaScript FileReader as shown in the code below.

function readExcel(currfile) {
  var reader = new FileReader();

  reader.onload = (function (_file) {
      return function (e) {
          //here should the magic happen
      };
  })(currfile);

  reader.onabort = function (e) {
      alert('File read canceled');
  };

  reader.readAsBinaryString(currfile);
}

I searched through the internet, but I could not get what I was looking for.


回答1:


You can use docxtemplater for this (even if normally, it is used for templating, it can also just get the text of the document) :

var zip = new JSZip(content);
var doc=new Docxtemplater().loadZip(zip)
var text= doc.getFullText();
console.log(text);

See the Doc for installation information (I'm the maintainer of this project)

However, it only handles docx, not doc



来源:https://stackoverflow.com/questions/44698896/javascript-library-to-read-doc-and-docx-on-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!