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?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With