0
我需要讀取文件(.doc),然後替換doc中的一些數據,然後發送到打印文檔(doc或pdf)。使用Javascript(Angular)閱讀,更改和保存文檔
第一步我嘗試從文檔中讀取數據。從.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>
和指導(上讀取文件) :
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/