0

i'm trying to read docx file

(function(){
var serverRelativeUrlOfMyFile = "/sites/sitecollection/mysite/assets/file.docx";
var req = new XMLHttpRequest();
req.onreadystatechange=handler;
req.open("GET", serverRelativeUrlOfMyFile, true); // params: (method, url, async)
req.send();
function handler(){
    if(req.readyState == 4 && req.status == 200){
        // you can now access the file content via the responseText property
        return req.responseText;
    }
}})();

But instead of text I get symbols. I need to get only text.

1 Answer 1

1

According to this answer on StackOverflow, you can do that with a JavaScript library called docxtemplater.

There are also other JS libraries out there to work with docx files.

After some quick research, it seems like docx4js can also read the contents of a file.

I personally use docx.js to generate documents, but I'm not sure if it can read the contents of an existing doc.

1
  • I am checking to see how things are going there on this issue. Jul 31, 2023 at 7:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.