- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2017 12:57 AM
How do I export a html table from a UI page via export to excel button? I'm trying to have a function called in html of UI page, this function is being called from client script of the same UI page. Where in client script is calling the script include which is having OOTB code for "export to excel context menu". find teh script include below:
script include:
var printing = Class.create();
printing.prototype = Object.extendsObject(AbstractAjaxProcessor, {
runContextAction : function() {
///log("query"); -------------------------------> when i check the log it is calling the script include.
@
var sysparm_rows = g_list.grandTotalRows;
var num_rows = parseInt(sysparm_rows);
var sysparm_query = g_list.getQuery({orderby: true, fixed: true});
gs.log("query=="+sysparm_query);----------------------------------> i dont find any log for this, i believe it is not able to pick up the row count from the UI Page.
var sysparm_view = g_list.view;
if (num_rows < g_export_warn_threshold) {
var dialog = new GwtPollDialog(g_list.tableName, sysparm_query, sysparm_rows, sysparm_view, 'unload_excel_xlsx');
dialog.execute();
return;
}
var dialog = new GwtExportScheduleDialog(g_list.tableName, sysparm_query, sysparm_rows, sysparm_view, 'unload_excel_xlsx');
dialog.execute();
return dialog;
},
type: 'printing'
});
Client script:
function xyz(){
var ga = new GlideAjax('labelprinting');
ga.addParam('sysparm_name','runContextAction');
//ga.addParam('sysparm_user_name',"Bob");
ga.getXML(runContext);
}
function runContext(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
Solved! Go to Solution.
- Labels:
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2017 01:31 AM
Hi Manisha,
You can try below code.it should work.
//excel export
function fnExcelReport() {
var tab_text = "<table border='2px'><tr bgcolor='#87AFC6'>";
var textRange;
var j = 0;
tab = document.getElementById('tableid'); // id of table
for (j = 0; j < tab.rows.length; j++) {
tab_text = tab_text + tab.rows[j].innerHTML + "</tr>";
//tab_text=tab_text+"</tr>";
tab_text = tab_text.replace(/Remove/i, "");
}
tab_text = tab_text + "</table>";
tab_text = tab_text.replace(/<A[^>]*>|<\/A>/g, ""); //remove if u want links in your table
tab_text = tab_text.replace(/<img[^>]*>/gi, ""); // remove if u want images in your table
tab_text = tab_text.replace(/<input[^>]*>|<\/input>/gi, ""); // reomves input params
//tab_text = tab_text.replace(/Remove/i, ""); // reomves theremove button label.
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) // If Internet Explorer
{
txtArea1.document.open("txt/html", "replace");
txtArea1.document.write(tab_text);
txtArea1.document.close();
txtArea1.focus();
sa = txtArea1.document.execCommand("SaveAs", true, "test.xls");
} else //other browser not tested on IE 11
sa = window.open('data:application/vnd.ms-excel,' + encodeURIComponent(tab_text));
return (sa);
}
Regards,
Prakash Ranjan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2017 03:53 AM
Hi Prakash,
It worked very well, thanks a lot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2017 06:36 AM
Hi Prakash,
When i use this code, it is not working on internet explorer. Basically the export to excel button is not exporting on IE.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2017 07:37 AM
Hi Prakash,
I could see the same code should be working for IE as well, but it is not taking MSIE value >0 from my internet explorer.
every time it is taking -1 even on IE. Could you please help me with this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2017 07:39 AM
Hi Manisha,
i need to check on this ..i will update you let me check..
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2017 12:13 AM
Hi Manisha
which version of IE you are using and whats the error you are getting can you please post that.
Thanks