Exporting to Excel straight from Html

posted Feb 4, 2014, 9:57 AM by Chad Boyer
While we have a great excel export engine and the reporting engine that will export to excel as well.  If you just want to quickly export to excel table data from a page you can use the following javascript code:

function showExcel() {
  document.getElementById('foot').innerHTML = "";
  document.getElementById('OptionMenu').innerHTML = "";
  document.getElementById('FilterRow').innerHTML = "";
  $$('td.filtercolumn').set('html','');
 
  window.open('data:application/vnd.ms-excel,' + encodeURIComponent(document.getElementById('MatrixViewDiv').innerHTML));

  qbo3.getObject('MatrixViewDiv').refresh(); 
}

This sample is from the Matrix.MatrixView.xslt.  Please see that xslt to show the divs but you can also see this on any Matrix Summary Page to see the div's involved.
We are calling this sample from the Options menu.  In the javascript we are removing the options menu the filter row as well as the footer.

The Inner Html call just opens that table code with excel which works.  It isn't the best formatted but quick and dirty html to excel is what this code does.

Comments