【发布时间】:2014-12-19 09:58:21
【问题描述】:
我需要读取文件(.doc),然后替换 doc 中的一些数据,然后发送到打印(doc 或 pdf)。
第一步,我尝试从文档中读取数据。从 .txt 它的工作,但从 .doc 没有:(
我在 jsfiddle http://jsfiddle.net/qo0fxo50/做了例子
我尝试这样做:
<h1>Select file</h1>
<input type="file" on-read-file="showContent($fileContent)" />
<div>
<h2>File content is:</h2>
<pre>{{ contentfile }}</pre>
</div>
And 指令(on-read-file):
directives.directive('onReadFile', function ($parse) {
return {
restrict: 'A',
scope: false,
link: function(scope, element, attrs) {
var fn = $parse(attrs.onReadFile);
element.on('change', function(onChangeEvent) {
var reader = new FileReader();
reader.readAsText((onChangeEvent.target).files[0], 'CP1251');
reader.onload = function(onLoadEvent) {
scope.$apply(function() {
fn(scope, {$fileContent:onLoadEvent.target.result});
});
};
});
}
};
});
我在 jsfiddle http://jsfiddle.net/qo0fxo50/做了例子
【问题讨论】:
标签: javascript angularjs angularjs-directive