Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export data from Oracle SQL Developer to Excel .xlsx

I have a small project where data from Oracle SQL Developer needs to be exported to Excel (using commands rather than tools in SLQ Developer), then create a graph. Using "spool" I can export to csv fine (but cant make a graph in csv) but when I try to export to xlsx it corrupts the whole excel sheet saying

"Excel cannot open the file "ExcelFile.xlsx" because the file format or file extention 
       is not valid. Verify that the file has not been corrupted and that the 
       file extension mathces the format of the file."

Here is the code I used in SQL Developer.

spool FileLocation\ExcelFile.xlsm
SELECT * FROM Table;
spool off;

Is there any way I can stop the data from becoming corrupted or is there another way to export data to a .xlsx file?

like image 225
IAmRapson Avatar asked Jun 23 '17 15:06

IAmRapson


2 Answers

Nooooooo.

set sqlformat csv
spool c:\file.sql
select * from table;
spool off;

then open the file in excel.

OR

Run your query interactively.

Right click on the grid, Export > XLSX. Open the file.

Spool only writes the query output to the file, it doesn't look at the file extension and figure out HOW to write the output at that point.

So you either have to code it yourself via the query, or use one of the format outputs we support

SET SQLFORMAT
  CSV
  JSON
  DELIMITED
  XML
  HTML
  INSERT
  LOADER

Use 'help set sqlformat' for help.

like image 173
thatjeffsmith Avatar answered Oct 08 '22 12:10

thatjeffsmith


Hi sql developer from what I know for exporting is using sqlplus(code is same) so perhabs there are other ways but this one should be good enough

I would try changing first line to look like this:

spool ExcelFile.xls

Probably you also need to turn on

SET MARKUP HTML ON

http://www.orahow.com/2015/09/spool-sqlplus-output-to-excel-format.html

Anyway there is workaround - you can just generate .CSV file and then open it in excel and save as .xlsx file

like image 40
kpazik Avatar answered Oct 08 '22 12:10

kpazik