jmaister / excellentexport Goto Github PK
View Code? Open in Web Editor NEWJavascript export to Excel
License: MIT License
Javascript export to Excel
License: MIT License
The compressed file:
"function" === typeof define && define.c ? define(function() {
return l
}) : "undefined" !== typeof exports ? ("undefined" !== typeof module && module.b && (exports = module.b = l), exports.a = l) : r.a = l
This is the only way to use:
<a download="2017-1-12.xls" href="javascript:;" class="btn" title="Download Excel" onclick="return a.excel(this, 'stockup', 'Sheet1');">Download</a>
Hi,
Do you plan to implement cells formatting? Like background color for example?
Thanks
Tried the script in IE. Doesn't work. I suspect its because IE doesn't support data protocol. Have you tested your script on an IE browser (cause I see you have mentioned that its IE compatible) ?
Using this with Tablesorter and using the Tablesorter Filter option it creates a row that looks like an Excel Filter but doesn't work like one. Need to leave out the Tablesorter Filter to export but if you could tell it to start on the 2nd row then it would work just fine.
Can this lib export multiple worksheets?
I propose to add a package.json file that would enable importing your wonderfull package directly by node (npm) package manager.
This project is simple enough and useable! Great!
But I think many usage is to export html table to excel report, so I think there is border in excel will be better for custom.
So if this project can config border or just set table style for border, it may be great.
We had incompatibilities with Office 2016, the same file in Office 2013 don't have problem.
var ee = {
/** @expose */
excel: function(anchor, table, name, filename) {
if (!filename) var filename = 'output.xls';
table = get(table);
var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML};
var isIE = /*@cc_on!@*/false || !!document.documentMode;
if((navigator.appVersion.indexOf("MSIE") >= 0) || (isIE == true)) {
myFrameTableDownloadIE.document.open("text/html", "replace");
myFrameTableDownloadIE.document.write(format(template.excel, ctx));
myFrameTableDownloadIE.document.close();
myFrameTableDownloadIE.focus();
myFrameTableDownloadIE.document.execCommand('SaveAs', true, filename);
} else {
var hrefvalue = uri.excel + base64(format(template.excel, ctx));
anchor.href = hrefvalue;
}
// Return true to allow the link to work
return true;
},
/** @expose */
csv: function(anchor, table, delimiter, newLine, filename) {
if (!filename) var filename = 'output.csv';
if (delimiter !== undefined && delimiter) {
csvDelimiter = delimiter;
}
if (newLine !== undefined && newLine) {
csvNewLine = newLine;
}
table = get(table);
var csvData = tableToCSV(table);
var isIE = /*@cc_on!@*/false || !!document.documentMode;
if((navigator.appVersion.indexOf("MSIE") >= 0) || (isIE == true)) {
myFrameTableDownloadIE.document.open("text/html", "replace");
myFrameTableDownloadIE.document.write(csvData);
myFrameTableDownloadIE.document.close();
myFrameTableDownloadIE.focus();
myFrameTableDownloadIE.document.execCommand('SaveAs', true, filename);
} else {
var hrefvalue = uri.csv + base64(csvData);
anchor.href = hrefvalue;
}
return true;
}
Cells containing newline characters will have text smashed together. This can be fixed with something like the code below. Note the use of col.innerText, which preserves newlines which can then be replaced in fixCSVField.
var fixCSVField = function(value) {
var fixedValue = value;
var addQuotes = (value.indexOf(csvDelimiter) !== -1) || (value.indexOf('\r') !== -1) || (value.indexOf('\n') !== -1);
var replaceDoubleQuotes = (value.indexOf('"') !== -1);
var replaceLineBreaksWithSpace = ((value.indexOf('\r') !== -1) || (value.indexOf('\n') !== -1));
if (replaceLineBreaksWithSpace) {
fixedValue = fixedValue.replace(/(\r\n|\n|\r)/gm," ");
}
if (replaceDoubleQuotes) {
fixedValue = fixedValue.replace(/"/g, '""');
}
if (addQuotes || replaceDoubleQuotes) {
fixedValue = '"' + fixedValue + '"';
}
return fixedValue;
};
var tableToCSV = function(table) {
var data = "";
var i, j, row, col;
for (i = 0; i < table.rows.length; i++) {
row = table.rows[i];
for (j = 0; j < row.cells.length; j++) {
col = row.cells[j];
data = data + (j ? csvDelimiter : '') + fixCSVField(col.innerText.trim());
}
data = data + csvNewLine;
}
return data;
};
If I am going to export large amount of data like 4000 rows then it will crashed.
What should i do to solve this issue?
Using the minified version of the master branch, when I call ExcellentExport.excel(this, 'exportMe', 'Sheet1');
or ExcellentExport.excel(this, 'exportMe');
the resulting Excel file has it's sheet named 'undefined'.
The un-minified script works as expected.
All other aspects of this script work great. Thanks for your work on this!
For what it's worth, this is in Chrome 35.0.1916.114 m
Hey @jmaister ,
we are using your cool solution but we encounter an issue, our MS Excel don't understand the ',' seperator so we want to change it to another one 'tab or ";"' can we do this easily with your solution? I didn't find anything in this direction in the readme.
Can I disable its functionality for empty table?
Thanks.
one column in HTML table has as href link, it dont want the hyperlinks to be copied to excel export. Is there any way to do that?
If your table header field name has &
in it then it will separate it out as two separate columns
Is it possible to embed an <img>
with base64 source into the Excel? ie. open the Excel with image show normally.
It works fine on MS Office and LibreOffice, but when opened using Numbers it just displays the table markup code not the actual formatted data.
I used the XLS file exported from the demo here: http://jordiburgos.com/post/2014/excellentexport-javascript-export-to-excel-csv.html
Getting this error.
15:30:54.009 TypeError: Argument 2 of URL.createObjectURL can't be converted to a dictionary. 1 excellentexport.min.js:8:419
I don't get this error in chrome or IE, for the same page.
Do you know why?
When i use in angular2 , export xml file and open it only loadding
E.g. when I tried to export to Excel in Safari the file name is always unknown. Same page is fine in Chrome.
As I am using Indic (Malayalam) fonts, the exported excel sheet is not rendered properly. Is it possible add some fonts like 'rachana' or 'dyuthi' which should be automatically rendered in the excel spreadsheet.
I let you find it :-)
Each cell that start with leading zero will output without the leading zero or zeros.
Can I pass the data as string to the new excel file?
Will be glad to find a solution. thanks!
Hello, we were testing in Firefox developer edition (Linux 64bits 52.0a2 now, but its same in FF stable) the index.html, but that does not work. That was the error:
TypeError: Argument 2 of URL.createObjectURL can't be converted to a dictionary.[Learn More] excellentexport.js:105:27
The "Learn More" is a link to https://developer.mozilla.org/docs/Web/JavaScript/Reference/Errors/No_properties?utm_source=mozilla&utm_medium=firefox-console-errors&utm_campaign=default
The problem is that window.URL.createObjectURL()
only receive one argument (the blob): https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL
Even if <x:DisplayGridlines/>
is present in xls template, gridlines are not shown when opened in Excel (Excel 2011 Mac OS).
I had to add <meta name=ProgId content=Excel.Sheet> <meta name=Generator content="Microsoft Excel 11">
to template, just before <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
to make them appear.
Looks like Office 2007 and beyond have an extension check that is getting triggered when running even the examples, causing an error "The file format differs from the format that the file name extension specifies"
I am try to find a way to export js array to excel(not csv). I would be appreciate a lot if excellentexport support this.
Thanks
I have an error when click Download
ReferenceError: \u0414\u0435\u043F\u043E\u0437\u0438\u0442\u044B is not defined
http://reports.maanimo.com/depozity/
What is wrong?
Hi does this library allow me to export a xls with a image somewhere on a sheet?
if there are any examples on the web showing this it would also be great..
thanks
James
Estou tendo problemas com acentuação. Alguma dica para resolver?!
enconding da página está em UTF-8.
office version : 2010
I want to export my html table to xlsx instead of xls. Any support for this?
When export to excel how to add the CSS class to any tr tags to ignore the specified table data while exporting.Is this possible?
I have a 73 column, 219 row table (yeah don't ask), trying to export it crashes Chrome, FYI.
(well it crashes the Chrome tab)
I'm using Node and Webpack and Babel to build/transpile.
import * as ExcellentExport from 'excellentexport/excellentexport'
import ExcellentExport from 'excellentexport/excellentexport'
import excellentexport from ExcellentExport from 'excellentexport'
None of these seem to work. Do you have an es6 example of importing a node-installed version?
Could you Publish this repo on NPM?
Hi, cool repo!
In my table, some <td>
may contain href
(might be javacript:void(0)
) , some may be set to display:none
, and I don't want them in the final .xls
file. So I'm wondering if there's any way to do it, by an option
for example ?
When trying to export both a CSV and Excel sheet, I get a 'Frame load interrupted' error in the console, and the file isn't downloaded.
So I have a column that I don't want to appear in the exported Excel file (this column contains buttons/links that only work on the web) -- Maybe mark cells to exclude with a certain CSS class or something. Like
<td data-excel-export-exclude="true">my buttons are here</td>
or something of the sort.
Hi @jmaister
I use https://rails-assets.org/ for package managing of JS libraries for my Ruby on Rails project and forced a problem with excellentexport gem generating. You can see it here. It writes "excellentexport has no versions defined. Please create an issue in component's repository.".
The problem is that you use 2-digit version number and this is not Semantic Versioning.
Could you please publish new github release with 3 digit (like 1.5.0)?
Any plan for Bower install?
Great Job!!
Find this line(in function csv):
var hrefvalue = uri.csv + base64(csvData);
change it to:
var hrefvalue = uri.csv + '77u/' + base64(csvData);
I have some cells that need to execute some JS, so the cell contains <script>var someJS = 'some value';</script>. When I export, "var someJS = 'some value';" is included in the Excel cell, which is not ideal. I've worked around this by adding additional checks in the regex to find <script></script> tags and add html comments around them so that Excel doesn't display them, but I'd like that built in so I don't have to use a custom version of the script.
Additional hacky code added around line 104 in the ExcellentExport function definition
// comment out scripts so the JS doesn't appear in Excel
c.table = c.table.replace(new RegExp("<script", "g"), function(m,p) {
return "<!-- <scr"+"ipt";
});
c.table = c.table.replace(new RegExp("</script>", "g"), function(m,p) {
return "</scr"+"ipt> -->";
});
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.