在我的Excel export.html我:在Excel角出口
<div class="config-menu-container first">
<div class="menu-title">
<span class="excel import">Excel import</span>
<span class="excel export">Excel Export</span>
</div>
<ul class="menu-body step2" id="exportable">
<li class="title">
<span class="label main order first」>1</span>
<span class="label main order second」>2</span>
<span class="label main order third」>3</span>
</li>
<li class="row" ng-repeat="device in devices">
<span class="label sub first" ng-bind="device.deviceId" ng-click="deviceScope = device.id"></span>
<span class="input second">
<custom-input type="text" width="330" height="24" model="device.name"></custom-input>
</span>
<span class="input third" ng-repeat-end>
<custom-input type="select2" width="462" height="24" label=「Select Device."
options="option.billingInfo" model="device.billingTargetId"></custom-input>
</span>
</li>
</ul>
</div>
在我的Excel export.directive.js我:
'use strict';
angular.module('bemsApp')
.directive('excelExport', function() {
return {
templateUrl: 'app/directives/excel-export/excel-export.html',
restrict: 'EA',
link: function (scope, element, attrs) {
scope.exportData = function() {
var blob = new Blob([document.getElementById('exportable').innerHTML], {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
});
saveAs(blob, "Report.xls");
};
}
};
});
當我嘗試保存Excel文件,則會發生錯誤saveAs沒有定義。
我不得不單獨定義saveAs函數,想知道是否有辦法保存Excel文件。
因爲FileSaver intervace從HTML5規範中刪除,則需要一個Filesaver.js庫。請參閱文檔http://updates.html5rocks.com/2011/08/Saving-generated-files-on-the-client-side – iiro 2015-03-31 05:23:59
「」標記不會起作用,如answer [here](http ://stackoverflow.com/questions/11336663/how-to-make-a-browser-display-a-save-as-dialog-so-the-user-can-save-the-conten)? – 2015-03-31 05:38:21
@iiro是正確的。但爲什麼不把它作爲答案,將upvote。 – deitch 2015-03-31 05:42:56