Search This Blog

Wednesday, June 17, 2020

Create Excel File From Classic Report in Oracle Apex Using Java Script

Create Excel File From Classic Report in Oracle Apex Using Java Script
1. Upload File 

Download File

2. Copy Pest the Code

<!DOCTYPE html>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>SheetJS JS-XLSX In-Browser HTML Table Export Demo</title>

<style>
.xport, .btn {
display: inline;
text-align:center;
}
a { text-decoration: none }
#data-table, #data-table th, #data-table td { border: 1px solid black }
</style>
<style type="text/css"></style></head>
<body>
<!--[if gt IE 9]-->
<script type="text/javascript" src="#APP_IMAGES#download/xlsx.full.min.js.download"></script>
<![endif]-->


<!--[if lte IE 9]>
<script type="text/javascript" src="shim.min.js"></script>
<script type="text/javascript" src="xlsx.full.min.js"></script>
<script type="text/javascript" src="Blob.js"></script>
<script type="text/javascript" src="FileSaver.js"></script>
<![endif]-->



<script>
function doit(type, fn, dl) {
var elt = document.getElementById('testid');
var wb = XLSX.utils.table_to_book(elt, {sheet:"Sheet JS"});
return dl ?
XLSX.write(wb, {bookType:type, bookSST:true, type: 'base64'}) :
XLSX.writeFile(wb, fn || ('Downloaded File.' + (type || 'xlsx')));
}
</script>

<br>
<pre><b>Export it!</b></pre>
<table id="xport">
<tbody><tr><td><pre>XLSX Excel 2007+ XML</pre></td><td>
<p id="xportxlsx" class="xport"><input type="submit" value="Export to XLSX!" onclick="doit(&#39;xlsx&#39;);"></p>
<p id="xlsxbtn" class="btn"></p>
</td></tr>
<tr><td><pre>XLSB Excel 2007+ Binary</pre></td><td>
<p id="xportxlsb" class="xport"><input type="submit" value="Export to XLSB!" onclick="doit(&#39;xlsb&#39;);"></p>
<p id="xlsbbtn" class="btn"></p>
</td></tr>
<tr><td><pre>Comma Separated Values</pre></td><td>
<p id="xportcsv" class="xport"><input type="submit" value="Export to CSV!" onclick="doit(&#39;csv&#39;);"></p>
<p id="csvbtn" class="btn"></p>
    
</td></tr>
</tbody></table>
</body></html>

3. Create Report Region And Set Static ID - testid

5 comments:

  1. Great Solution! is any wayt to put some color and titles with sorting function in the XLSX?? Best Regards from Athens Greece

    ReplyDelete
  2. Hi Abdul,

    Thanks for this good method. But how to eliminate the first row which is blank and the last two rows which contains page numbers?

    If those unnecessary records are eliminated, then it would be helpful for me actually.
    Because from my download, the report will be uploaded to another system. For that upload, first row should be header. and post the last record no extra data should be there.

    Can you help me something on this?

    Thanks and Regards,
    Shree

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. hi thanks for your doing best i did your instructions but the file didn't download and the page just refresh. im use apex 18.1
    so whats wrong with it?
    and if you do not mind i need help for uploading data from xlsx files too. can you help me?

    ReplyDelete

Restrict File Upload by File Type in Oracle Apex

If you want to restrict file upload by file type/extension/format you can follow the below steps.  Goto File Browser Item --> Advanced --...