简体   繁体   中英

Display word file content in textarea using javascript

I am trying to display word file content in textarea but it gives me output like this

在此处输入图片说明 Here is my code

vm.uploadDoc = function () {
        var file = document.getElementById("docFile").files[0];
        var fileReader = new FileReader();
        fileReader.onload = function(fileLoadedEvent){
            var textFromFileLoaded = fileLoadedEvent.target.result;
            document.getElementById("inputTextToSave").value = textFromFileLoaded;
        };

        fileReader.readAsText(file, "UTF-8");
    };

I want to display actual content of word file. What I am doing wrong here?

you can try this code.

<html>

<head><title>snook.ca load document</title>

<script language="JavaScript">

<!--//

function loadworddoc(){

  var doc = new ActiveXObject("Word.Application"); // creates the word object

  doc.Visible=false; // doesn't display Word window

  doc.Documents.Open("C:\\My Documents\\file.doc"); // specify path to document



  //copy the content from my word document and throw it into my variable

  var txt;

  txt = doc.Documents("C:\\My Documents\\file.doc").Content; 

  document.all.myarea.value = txt;

  doc.quit(0); // quit word (very important or you'll quickly chew up memory!)

}

//-->

</script>

</head>

<body>

  <p><input type=button onClick="loadworddoc();" value="Load">

  <p><textarea name=myarea cols=50 rows=5>nothing here yet</textarea>

</body>

</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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