Skip to content

Commit 8518ff0

Browse files
authored
Create exportexcel.js
Simple download excel file with the content of a DIV or TABLE element and lauch direct download without depends third library
1 parent c7a08f7 commit 8518ff0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

exportExcel.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//Requires use of jQuery library, you can modify to pure Javascript instead
2+
3+
// Create a Blob of the content of $element (table, div) and passes
4+
// into a virtual file to make direct download
5+
// Creates an 'a' elements and fire the download with parameters of URL
6+
// that contains Blob file and fires fclick event
7+
8+
function exportExcel(element) {
9+
let file = new Blob([$(element).html()],{type:'application/vnd.ms-excel'})
10+
let url = URL.createObjectURL(file)
11+
let a = $('<a />', {
12+
href: url,
13+
download: 'file.xls'
14+
}).appendTo('body').get(0).click()
15+
}

0 commit comments

Comments
 (0)