Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
Hi all experts,
I try to use btob in my js to export html's table to excel.
i added this code in my js
base64 = function (s) { return window.btob(unescape(encodeURIComponent(s))) }
but for this code, it works only Firefox,Chrome and it doesn't work with IE.
When i debug IE, it displays me an error like this: Object doesn't support property or method 'btob'
I found that this method "btob" is for firefox, chrome to use only.
so does anybody know that how can do or replace this method to let IE,Chrome,Firefox work?

Thanks

TONY
Posted
Comments
Sergey Alexandrovich Kryukov 15-Aug-13 8:41am    
Where did you get this 'btob'? If you are asking how to replace a method, don't you think you need to explain what you want to achieve?
—SA

1 solution

Here is the pure javascript solution.Check this out.

XML
<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]--></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 (!t


DEMO

http://jsfiddle.net/insin/cmewv/[^]

For more info check this :

http://stackoverflow.com/questions/14125819/export-html-table-to-excel-but-select-a-name-for-the-file[^]

UPDATE

Export table data to Excel using jQuery

http://jquerybyexample.blogspot.com/2012/10/export-table-data-to-excel-using-jquery.html[^]

NOTE: If you need to work above code on IE then,

Quote:
you need to set response header. If you are using ASP.NET then

Response.AddHeader("Content-Disposition", "attachment;filename=download.xls");


I hope this will help to you.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900