0

I made one JSBIN and things are working fine but the problem is, I cant rename the file and add extension.

Another problem is the data is only from static DOM not from the ng-repeat I put using controller.

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 Goes here like

<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>
fruitjs
  • 745
  • 2
  • 10
  • 25

2 Answers2

0

Check this thread whether your question is related this one

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

Community
  • 1
  • 1
vignesh
  • 151
  • 6
0

forming an excel at client side has limitations.you can try apache poi to make the file at server side and fetch it. if you want to go client side then this link might help

Export to xls using angularjs

Community
  • 1
  • 1
Avinash Solanki
  • 1,091
  • 1
  • 10
  • 19