HTML:
Export to Excel
Export to Excel
CSS:
/* Styles go here */
.table-header
{
background-color: lightskyblue;
}
JAVASCRIPT:
// Code goes here
var myApp=angular.module("myApp",[]);
myApp.factory('Excel',function($window){
var uri='data:application/vnd.ms-excel;base64,',
template='{table}
',
base64=function(s){return $window.btoa(unescape(encodeURIComponent(s)));},
format=function(s,c){return s.replace(/{(\w+)}/g,function(m,p){return c[p];})};
return {
tableToExcel:function(tableId,worksheetName){
var table=$(tableId),
ctx={worksheet:worksheetName,table:table.html()},
href=uri+base64(format(template,ctx));
return href;
}
};
})
.controller('MyCtrl',function(Excel,$timeout,$scope){
$scope.exportToExcel=function(tableId){ // ex: '#my-table'
var exportHref=Excel.tableToExcel(tableId,'WireWorkbenchDataExport');
$timeout(function(){location.href=exportHref;},100); // trigger download
}
});
No comments:
Post a Comment
Dharamart.blogspot.in