Search This Blog

Wednesday, April 25, 2018

How to Generate and Download Text File By Oracle Apex 5.1 Using JavaScript

It is very easy to generate a text file from oracle apex by using JavaScript . Here I describe it step by step.

1.  First create a page and create a region with (Type: Static Content).
2. Create a textarea type item. (Name: P21_CONTENT ) 
3. Then copy-pest the JavaScript code into  Page >>JavaScript >>Function and Global Variable        Declaration. 

(function () {
var textFile = null,
  makeTextFile = function (text) {
    var data = new Blob([text], {type: 'text/plain'});
    if (textFile !== null) {
      window.URL.revokeObjectURL(textFile);
    }
    textFile = window.URL.createObjectURL(data);
    return textFile;
  };
  var create = document.getElementById('create'),
    textbox = document.getElementById('P21_CONTENT');

    var link = document.getElementById('downloadlink');
    link.href = makeTextFile(textbox.value);
   link.style.display = 'block';
})();


4.  P21_CONTENT it is the CSS  ID of  P21_CONTENT of  textarea item.

5. Create a button with Behavior>>Action>>Submit Page. And another one button for clearing the data of the textarea.  

6. Then  copy-pest the HTML code into the Region >> Source 

   <a download="info.txt" id="downloadlink" width="107" 
   height="10" ><b>Download</b></a> 

JOB DONE...

Now you can see a page like this. Here you write any thing on the textarea and click on Generate Text button.  Finally Click on Download link.

Demo:

1.


2.


If Not Working You One Please Comment or Contact With Me.
For any type of mistake Advance Sorry and Please inform me.


5 comments:

  1. HI, thanks for this, Qaium. Is it possible to perform step 6 in an APEX Button rather than in a link?

    ReplyDelete
  2. This doesn't seem to work. It returns a NULL value from the element.

    ReplyDelete
  3. professionally Text file generated from Oracle table not typed on keyboard and generate Text file

    ReplyDelete

Error From Interactive Grid - Process ' Process- Save Interactive Grid Data' raised 'ORA-0000: normal, successful completion' while performing row locking.

Error: Process ' Process- Save Interactive Grid Data' raised 'ORA-0000: normal, successful completion' while performing row ...