Skip to Main Content
PLUG-INS
Long report into columns
Resizing dialog
Copy to clipboard
Time Touch Input
Restrict Shuttle
Copy Down
Store location
GENERATORS
Pipelined Function Generator
Generate substitution code
Generate getter and setter
Rewrite Query Parameters
Log statement
Align text on characters
Format APEX region source query
Format query
APEX EXAMPLES
Apex 5.0 Icons
Apex 5.1 Font Icons
Disabling items in tabular form
Usage Map
Excel Export
Export formatted content to Excel without printing engine
This page demonstrates how HTML content can be exported to excel without losing the formatting.
First the content of the demo report is copied into an APEX item and made suitable for Excel import. This is done using custom JavaScript (see JavaScript tab).
Then the page is submitted with the request EXPORT_EXCEL and upon load the content of the APEX item containing the HTML is downloaded as a file.
Info
More information in
this blogpost
Demo Report
Generate HTML content
Export content to Excel
report error: ORA-00942: table or view does not exist
HTML content
Content
APEX objects
Before Header Process
declare l_mime varchar2 (255); l_length number; l_file_name varchar2 (2000) := 'xls_export.xls'; l_blob blob; begin dbms_lob.createtemporary(l_blob, true); dbms_lob.write(l_blob, length(:p850_content), 1, utl_raw.cast_to_raw(:p850_content)); owa_util.mime_header ('application/xls', false); htp.p ('Content-Length: ' || dbms_lob.getlength(l_blob)); htp.p ('Content-Disposition: attachment; filename="'||l_file_name||'"'); owa_util.http_header_close; wpg_docload.download_file(l_blob); end;
Javascript of Dynamic Action to generate report
get_content(); apex.submit('EXPORT_EXCEL');
Branch
Process point
After processing
Sequence
-1
Target > Target
850
Targte > Advanced > Request
EXPORT_EXCEL
Condition > Type
Request = Value
Condition > Value
EXPORT_EXCEL
JavaScript
Page Level JavaScript
// remove the given class from all elements within the table function remove_class(table,p_class) { $(table).find('.'+p_class).each( function() { $(this).removeClass(p_class);}) } // convert input element in table cells to plain text function input2text(selector) { $(selector).find('input').each( function() { var td = $(this).closest('td'); var value = $(this).val(); $(td).text(value); } ); } // define the styles for your Excel cells here function get_style() { return(`.subheader {background-color: #B0B0B0; } `); } // copy the table, convert elements and apply styling function get_content() { var table = $('#emp_report .t-Report-report').clone(); // remove standard report table cell classes remove_class(table,'t-Report-cell'); remove_class(table,'t-Report-colHead'); // convert input elements to plain text input2text(table); // apply class hidden to subheader column to hide it $(table).find('#SUBHEADER,[headers="SUBHEADER"]').remove(); // apply a colspan of 7 to the subheaders $(table).find('.subheader').each( function() { $(this).attr('colspan','7') }); // wrap the table into a html/head structure with style definitions var content = `<html><head><style>${get_style()}</style><head><body>${$(table)[0].outerHTML}</body></html>` // copy the content to the APEX item P850_CONTENT apex.item('P850_CONTENT').setValue( content); }