Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add option for different extension name (xls or xlsx)
The new option can be used by declaring & using the "filetype" prop when declaring the component, valid options are "xls" and "xlsx".
  • Loading branch information
dqve authored Jan 8, 2021
commit 6a5ac42dfa0838773df4ebd54f206b1e590504d5
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
var propTypes = {
table: _propTypes2.default.string.isRequired,
filename: _propTypes2.default.string.isRequired,
filetype: _propTypes2.default.string.isRequired,
sheet: _propTypes2.default.string.isRequired,
id: _propTypes2.default.string,
className: _propTypes2.default.string,
Expand Down Expand Up @@ -71,7 +72,8 @@ var ReactHTMLTableToExcel = function (_Component) {

var table = document.getElementById(this.props.table).outerHTML;
var sheet = String(this.props.sheet);
var filename = String(this.props.filename) + '.xls';
var filetype = String((this.props.filetype)?(this.props.filetype == 'xlsx'?'xlsx':'xls'):'xls')
var filename = String(this.props.filename) + '.' + filetype;

var uri = 'data:application/vnd.ms-excel;base64,';
var template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-mic' + 'rosoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><meta cha' + 'rset="UTF-8"><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:Exce' + 'lWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/>' + '</x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></' + 'xml><![endif]--></head><body>{table}</body></html>';
Expand Down