title: Writing output of query to .xlsx from a stored procedure in SQL Developer
body: <p>I am needing to replace my current process of creating procedures in SQL Developer to write the output of a query into a CSV, with code that will output a .xlsx file instead. I've done some cursory research on the topic, but answers seem way over my head. </p>
  
  <p>I've tried to mimic solutions I found on google/stack overflow to no avail.</p>
  
  <p>EXAMPLE OF CSV PROCEDURE:</p>
  
  <pre><code>create or replace PROCEDURE EXAMPLE_FILE_CSV AS
    CURSOR c_data IS
                         ‘QUERY HERE’;
  
    v_file  UTL_FILE.FILE_TYPE;
  BEGIN
    v_file := UTL_FILE.FOPEN(location     =&gt; 'EXTRACT_DIR',
                             filename     =&gt; 'EXAMPLE_FILE.CSV',
                             open_mode    =&gt; 'w',
                             max_linesize =&gt; 32767);
    FOR cur_rec IN c_data LOOP
      UTL_FILE.PUT_LINE(v_file,
                        cur_rec.COL1   || ',' ||
                        cur_rec.COL2    || ',' ||
                        cur_rec.COL3      || ',' ||
                        cur_rec.COL4      || ',' ||
                        cur_rec.COL5 || ',' ||
                        cur_rec.COL6    ;
    END LOOP;
    UTL_FILE.FCLOSE(v_file);
  
  EXCEPTION
    WHEN OTHERS THEN
      UTL_FILE.FCLOSE(v_file);
      RAISE;
  END;
  </code></pre>