【问题标题】:Export excel in javascript用javascript导出excel
【发布时间】:2015-06-05 11:58:11
【问题描述】:

我创建了一个JSBIN,一切正常,但问题是,我无法重命名文件并添加扩展名。

另一个问题是数据仅来自静态 DOM,而不是来自我使用控制器放置的 ng-repeat。

var app = angular.module('app', []);
app.controller('ctrl', function($scope) {

    $scope.data = [{
        one: "Column One",
        two: "Column Two",
        three: "Column Three"
    }, {
        one: "Column One",
        two: "Column Two",
        three: "Column Three"
    }, {
        one: "Column One",
        two: "Column Two",
        three: "Column Three"
    }];

});


app.directive("myExportData", function() {
    return {
        restrict: "EA",
        link: function(scope, ele, attr) {
            ele.attr('value', "Export Table data into Excel");
            ele.bind('click', function() {
                console.log($('#dvData').html());
                window.open('data:application/vnd.ms-excel,' + $('#dvData').html());

            });

        }
    };
});

HTML 类似

<body ng-controller="ctrl">
    <div id="dvData">
        <table>
            <tr>
                <th>One</th>
                <th>Two</th>
                <th>Three</th>
            </tr>

            <tr ng-repeat="obj in data">
                <td>{{obj.one}}</td>
                <td>{{obj.two}}</td>
                <td>{{obj.three}}</td>
            </tr>


        </table>
        <input my-export-data type="button" id="btnExport" />
    </div>
</body>

【问题讨论】:

    标签: javascript angularjs


    【解决方案1】:

    检查这个帖子你的问题是否与这个有关

    How to change the name of file while exporting data to Excel?

    【讨论】:

      【解决方案2】:

      在客户端形成一个 excel 有限制。你可以尝试 apache poi 在服务器端制作文件并获取它。如果你想去客户端,那么这个链接可能会有所帮助

      Export to xls using angularjs

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-08-29
        • 2013-03-11
        • 2011-12-30
        • 2017-10-11
        • 2016-08-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多