html table to excel javascript
JavaScript
<script type="text/javascript">
var tableToExcel = (function() {
var uri = 'data:application/vnd.ms-excel;base64,'
, template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--><meta http-equiv="content-type" content="text/plain; charset=UTF-8"/></head><body><table>{table}</table></body></html>'
, 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 function(table, name) {
if (!table.nodeType) table = document.getElementById(table)
var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
window.location.href = uri + base64(format(template, ctx))
}
})()
</script> <button type="button" id="export" onclick="exportTableToExcel('tblData')">Export List</button>
<script>
function exportTableToExcel(tableID, filename = '') {
var downloadLink;
var dataType = 'application/vnd.ms-excel';
var tableSelect = document.getElementById(tableID);
var tableHTML = tableSelect.outerHTML.replace(/ /g, '%20');
// Specify file name
filename = filename ? filename + '.xls' : 'excel_data.xls';
// Create download link element
downloadLink = document.createElement("a");
document.body.appendChild(downloadLink);
if (navigator.msSaveOrOpenBlob) {
var blob = new Blob(['\ufeff', tableHTML], {
type: dataType
});
navigator.msSaveOrOpenBlob(blob, filename);
} else {
// Create a link to the file
downloadLink.href = 'data:' + dataType + ', ' + tableHTML;
// Setting the file name
downloadLink.download = filename;
//triggering the function
downloadLink.click();
}
}
</script>
Also in JavaScript:
- Title
- express bodyparser deprecated
- Category
- JavaScript
- Title
- how to sort array least to greatest javascript stACK
- Category
- JavaScript
- Title
- how to get the last element in javascript
- Category
- JavaScript
- Title
- how to empty form after submit react
- Category
- JavaScript
- Title
- express get query params from url
- Category
- JavaScript
- Title
- angular cli create component
- Category
- JavaScript
- Title
- chart.js data from mysql vanila javscript
- Category
- JavaScript
- Title
- clear scene\
- Category
- JavaScript
- Title
- anagram javascript example
- Category
- JavaScript
- Title
- capitalize first letter javascript
- Category
- JavaScript
- Title
- how to add element in json object
- Category
- JavaScript
- Title
- event handler attachment jquery
- Category
- JavaScript
- Title
- how to deploy react app in tomcat server
- Category
- JavaScript
- Title
- apache log format json
- Category
- JavaScript
- Title
- how to make a circle in js
- Category
- JavaScript
- Title
- component navigation without changin the url react router
- Category
- JavaScript
- Title
- clone a JavaScript object
- Category
- JavaScript
- Title
- discord.js
- Category
- JavaScript
- Title
- how to get today date in javascript
- Category
- JavaScript
- Title
- get react version
- Category
- JavaScript
- Title
- javascript .firstordefault
- Category
- JavaScript
- Title
- delete previous line node
- Category
- JavaScript
- Title
- Add table row in jQuery
- Category
- JavaScript
- Title
- how to get data in json format in javascript
- Category
- JavaScript
- Title
- drupal 8 node has field
- Category
- JavaScript
- Title
- how to add two number using jqueryu
- Category
- JavaScript
- Title
- adding a variable to a string without using + in javascript
- Category
- JavaScript
- Title
- angular list contains property
- Category
- JavaScript
- Title
- how to print console in javascript
- Category
- JavaScript
- Title
- angular material table
- Category
- JavaScript
- Title
- export component in
- Category
- JavaScript
- Title
- chart.js line chart
- Category
- JavaScript
- Title
- flatten an array in javascript
- Category
- JavaScript
- Title
- adonisjs vscode debugger
- Category
- JavaScript
- Title
- angular run with proxy
- Category
- JavaScript
- Title
- chart.js label word wrap
- Category
- JavaScript
- Title
- how to generate random string in javascript
- Category
- JavaScript
- Title
- how to check if object has key javascript
- Category
- JavaScript
- Title
- change text of element js
- Category
- JavaScript
- Title
- creating a 2d array in js
- Category
- JavaScript
- Title
- installing bootstrap in angular 9
- Category
- JavaScript
- Title
- get month in two digit in javascript date
- Category
- JavaScript
- Title
- empty a select input using js
- Category
- JavaScript
- Title
- comment out in javascript
- Category
- JavaScript
- Title
- delete with unlinksync node
- Category
- JavaScript
- Title
- javascript array remove duplicates
- Category
- JavaScript
- Title
- how to add array numbers in javascript
- Category
- JavaScript
- Title
- how to render different pages in nodes
- Category
- JavaScript
- Title
- how to return a string x amount in javascript without using . repeat
- Category
- JavaScript
- Title
- file input disable open file picker javascript
- Category
- JavaScript
- Title
- bind and unbind jquery validation
- Category
- JavaScript
- Title
- axios post with header
- Category
- JavaScript
- Title
- get iso date javascript
- Category
- JavaScript
- Title
- include gif in react
- Category
- JavaScript
- Title
- dropzone add download button addedfile
- Category
- JavaScript
- Title
- angular npm angular material
- Category
- JavaScript
- Title
- angular build production
- Category
- JavaScript
- Title
- how to get user ip address in javascript
- Category
- JavaScript
- Title
- How to abreviate digits in js
- Category
- JavaScript
- Title
- how to name a javascript variable
- Category
- JavaScript
- Title
- deploy angular app on google app engine
- Category
- JavaScript
- Title
- default pool size in sequelize
- Category
- JavaScript
- Title
- javascript ascii to hex
- Category
- JavaScript
- Title
- event.stoppropagation
- Category
- JavaScript
- Title
- change bloodhound remote dynamically
- Category
- JavaScript
- Title
- if clicked outside of div jquery
- Category
- JavaScript
- Title
- convert string to char array javascript
- Category
- JavaScript
- Title
- how to code print in javascript
- Category
- JavaScript
- Title
- history.pushstate
- Category
- JavaScript
- Title
- ionic (Emitted value instead of an instance of Error
- Category
- JavaScript
- Title
- check array values equal js
- Category
- JavaScript
- Title
- how to add button react native app.js
- Category
- JavaScript
- Title
- add class javascript
- Category
- JavaScript
- Title
- angular event emitter
- Category
- JavaScript
- Title
- int cating javascript
- Category
- JavaScript
- Title
- bubble sort javascript
- Category
- JavaScript
- Title
- get string of element
- Category
- JavaScript
- Title
- count value a to b character javascript
- Category
- JavaScript
- Title
- async await javascript stack overflow
- Category
- JavaScript
- Title
- how to make a property important in javascript
- Category
- JavaScript
- Title
- get current screen name react navigation
- Category
- JavaScript
- Title
- generate thumbnail of pdf using pf js
- Category
- JavaScript
- Title
- day to week
- Category
- JavaScript
- Title
- javascript adding an array to an array
- Category
- JavaScript
- Title
- drupal 8 check if current page is node
- Category
- JavaScript
- Title
- express server replit
- Category
- JavaScript
- Title
- iframe loader jquery
- Category
- JavaScript
- Title
- flip a coin javascript
- Category
- JavaScript
- Title
- event target javascript
- Category
- JavaScript
- Title
- how to get the height of window in javascript
- Category
- JavaScript
- Title
- Javascript - Track mouse position
- Category
- JavaScript
- Title
- chart js rotating the x axis labels
- Category
- JavaScript
- Title
- Finding HTML Element by Id
- Category
- JavaScript
- Title
- ion-fab-button ionic angular
- Category
- JavaScript
- Title
- get the id of a div in jquery
- Category
- JavaScript
- Title
- how to paste in input field react native
- Category
- JavaScript
- Title
- change select value jquery
- Category
- JavaScript
- Title
- enable disable click on div jquery
- Category
- JavaScript
- Title
- atom javascript es6 linter
- Category
- JavaScript
- Title
- how to check reactjs version in command prompt
- Category
- JavaScript