查看.doc文件 [英] Viewing the .doc file
本文介绍了查看.doc文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一个应用程序,我需要直接从文件系统中获取.doc或.docx文件并将其加载到页面上。你可以帮我解决这些代码吗?
打开这些文件时使用普通文件阅读器有问题,有人可以澄清为什么会这样吗?>
文件阅读器代码的一部分:
< !DOCTYPE < span class =code-attribute> HTML >
< html >
< head >
< meta http-equiv = X-UA兼容 content = IE =边缘 >
< script src = resources / sap-ui-core.js
< span class =code-attribute> id = sap-ui-bootstrap
data-sap-ui-libs = sap.ui.commons
data-sap-ui-theme = sap_goldreflection >
< / script > ;
<! - 添加闷棍.ui.table,sap.ui.ux3和/或data-sap-ui-libs的其他库(如果需要) - >
< body >
< 输入 类型 = file id = < span class =code-keyword> files name = file / >
< div id = byte_content > < / div >
< 脚本 >
function readBlob(){
var files = document .getElementById(' files')。files;
if (!files.length){
alert(' 请选择一个文件!');
return ;
}
var file = files [ 0 ];
var start = 0 ;
var stop = file.size - 1 ;
var reader = new FileReader();
// 如果我们使用onloadend,我们需要检查readyState。
reader.onloadend = function (evt){
if (evt.target .readyState == FileReader.DONE){ // DONE == 2
document .getElementById(' byte_content')。textContent = evt.target.result;
}
};
var blob = file.slice(start,stop + 1 );
reader.readAsBinaryString(blob);
}
$( document)。ready( function (){
$( #files)。change( function (){
readBlob();
}) ;
});
< / script >
< / body >
< / html >
解决方案
( document ).ready( function (){
( < span class =code-string>#files)。change( function (){
readBlob();
});
});
< / script >
< / body >
< / html >
i am making an application in which i need to directly pick up the .doc or .docx files from the file system and load them on the page. Can you help me with the code ?
There is a problem with using a normal file reader in opening these files , can anyone clarify why is it happenning ?
part of the code for file reader:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<script src="resources/sap-ui-core.js"
id="sap-ui-bootstrap"
data-sap-ui-libs="sap.ui.commons"
data-sap-ui-theme="sap_goldreflection">
</script>
<!-- add sap.ui.table,sap.ui.ux3 and/or other libraries to 'data-sap-ui-libs' if required -->
<body>
<input type="file" id="files" name="file" />
<div id="byte_content"></div>
<script>
function readBlob() {
var files = document.getElementById('files').files;
if (!files.length) {
alert('Please select a file!');
return;
}
var file = files[0];
var start = 0;
var stop = file.size - 1;
var reader = new FileReader();
// If we use onloadend, we need to check the readyState.
reader.onloadend = function(evt) {
if (evt.target.readyState == FileReader.DONE) { // DONE == 2
document.getElementById('byte_content').textContent = evt.target.result;
}
};
var blob = file.slice(start, stop + 1);
reader.readAsBinaryString(blob);
}
$("document").ready(function(){
$("#files").change(function() {
readBlob();
});
});
</script>
</body>
</html>
解决方案
("document").ready(function(){
("#files").change(function() { readBlob(); }); }); </script> </body> </html>
这篇关于查看.doc文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文