There are multiple ways to achieve this, but one possible solution is:
$scope.tableData = {
title: "My Table",
rows: [
{col1: "Row 1 Column 1", col2: "Row 1 Column 2"},
{col1: "Row 2 Column 1", col2: "Row 2 Column 2"},
{col1: "", col2: ""}, // empty row
{col1: "", col2: ""} // empty row
]
};
npm install xlsx --save
$scope.exportToExcel = function() {
var wb = XLSX.utils.book_new();
var ws = XLSX.utils.json_to_sheet([$scope.tableData.title], {header:[""]}); // title row
XLSX.utils.sheet_add_json(ws, $scope.tableData.rows, {skipHeader:true, origin:"A2"}); // table rows
wb.Sheets["Sheet1"] = ws;
var wbout = XLSX.write(wb, {bookType:"xlsx", type:"binary"});
saveAs(new Blob([s2ab(wbout)],{type:"application/octet-stream"}), "mytable.xlsx"); // save as file
};
<button ng-click="exportToExcel()">Export to Excel</button>
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2022-09-14 11:00:00 +0000
Seen: 16 times
Last updated: Mar 30 '22
What is the solution to enable syntax highlighting of template literals for styled components?
What is the solution for the error "Cannot find module 'fsevents'" while using Vite on Windows?
What is the solution to the version error of Laravel guzzlehttp/guzzle?
What is the solution to the error "Django TemplateDoesNotExist" occurring at accounts/login.html?