angular 在 excel 出口

angular in excel export

在我的 excel-export.html 我有:

<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 did not define.

我必须单独定义 saveAs 函数,想知道是否有办法保存 Excel 文件。

您需要一个 Filesaver.js 库,因为 FileSaver 接口已从 html5 规范中删除。请参阅文档

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