Rahul Chidgopkar
Posts: 0
Joined: Tue May 14, 2013 7:11 am

Need help generating excel from grid table

Hi,

I don't know if this is an Appery question or a JS question, so please bear with me. I've built a mobile website using Appery and one of the functionality is to download the grid displayed on page as an excel, preferably with formatting. This is my grid:
http://prntscr.com/1d3ivg

I'm generating the grid using Rest Service mapping like this - http://prntscr.com/1d3j3j

I found a nifty little JS solution for excel download - https://gist.github.com/insin/1031969

But it doesn't work because each row in Rest response generates a new table. I want to get this working, but Rest service mapping is clearly not the solution. Can you please advise how to do it?

Thanks,
Rahul.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Need help generating excel from grid table

Hello! Working on it. I'll update.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Need help generating excel from grid table

Hi, with a link you've posted doesn't actually generates excel file, there just forms html file with the following head: code<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http:&#47;&#47;www&#46;w3&#46;org&#47;TR&#47;REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>W3C Example Table<&#47;x:Name><x:WorksheetOptions><x:DisplayGridlines&#47;><&#47;x:WorksheetOptions><&#47;x:ExcelWorksheet><&#47;x:ExcelWorksheets><&#47;x:ExcelWorkbook><&#47;xml><![endif]--><&#47;head>/code
so you can't use this code as while maping it generates several tables. You would need to modify your code:
codevar tableToExcel = (function() {
var uri = 'data:application&#47;vnd&#46;ms-excel;base64,'
, template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http:&#47;&#47;www&#46;w3&#46;org&#47;TR&#47;REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}<&#47;x:Name><x:WorksheetOptions><x:DisplayGridlines&#47;><&#47;x:WorksheetOptions><&#47;x:ExcelWorksheet><&#47;x:ExcelWorksheets><&#47;x:ExcelWorkbook><&#47;xml><![endif]--><&#47;head><body><table>{table}<&#47;table><&#47;body><&#47;html>'
, base64 = function(s) { return window&#46;btoa(unescape(encodeURIComponent(s))) }
, format = function(s, c) { return s&#46;replace(&#47;{(\w+)}&#47;g, function(m, p) { return c[p]; }) }
return function(table, name) {
var output = '';
&#47;&#47;gt(0) - to skip first table&#46; it is hidden table, used for mapping
$("[name=" + table + "]:gt(0)")&#46;each(function(){
output += $(this)&#46;find("tbody")&#46;html();
});
var ctx = {worksheet: name || 'Worksheet', table: output}

Code: Select all

 window&#46;location&#46;href = uri + base64(format(template, ctx)) 

}
})()/code

to call that function you should pass table name
codetableToExcel('mobilegridName', 'W3C Example Table');/code

Rahul Chidgopkar
Posts: 0
Joined: Tue May 14, 2013 7:11 am

Need help generating excel from grid table

I tried this. It works fantastically well. Thank you so much for your awesome support.

Return to “Issues”