2015-03-31 35 views
3

在我的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文件。

+2

因为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

回答

4

您需要一个Filesaver.js库,因为FileSaver接口已从html5规格中删除。看到该文档

http://updates.html5rocks.com/2011/08/Saving-generated-files-on-the-client-side

+0

我到目前为止成功的是创建一个包含Filesaver.js的Excel文件。所以你打开一个Excel文件,而不是一个HTML标签,这个数据输入不变。为了以Excel格式输出,您希望以其他方式执行此操作吗? – bismute 2015-03-31 07:04:55

+0

@bismute抱歉,但我不明白你的意思是什么?你能澄清一点吗? – iiro 2015-03-31 07:19:46