在javascript中导出excel
我做了一个,一切正常,但问题是,我不能重命名文件和添加扩展名 另一个问题是数据仅来自静态DOM,而不是来自我使用控制器放置的ng repeat在javascript中导出excel,javascript,angularjs,Javascript,Angularjs,我做了一个,一切正常,但问题是,我不能重命名文件和添加扩展名 另一个问题是数据仅来自静态DOM,而不是来自我使用控制器放置的ng repeat var app = angular.module('app', []); app.controller('ctrl', function($scope) { $scope.data = [{ one: "Column One", two: "Column Two", three: "Column
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>
一个
两个
三
{{obj.one}
{{obj.two}
{{obj.three}}
检查此线程您的问题是否与此相关
在客户端生成excel有局限性。您可以尝试使用apache poi在服务器端生成文件并获取它。如果您想转到客户端,那么此链接可能会有所帮助