Export data from Oracle SQL Developer to Excel .xlsx Export data from Oracle SQL Developer to Excel .xlsx oracle oracle

Export data from Oracle SQL Developer to Excel .xlsx


Nooooooo.

set sqlformat csvspool c:\file.sqlselect * 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


I was also facing the same problem then applied below code and it exported successfully..

import xlsxwriterfrom xlsxwriter import Workbookimport cx_Oracleimport datetimefrom datetime import datedsn_tns = cx_Oracle.makedsn('HOST', 'PORTNO', sid='BGRDB')     db = cx_Oracle.connect(user=r'username', password='password', dsn=dsn_tns)cursor = db.cursor()workbook = xlsxwriter.Workbook('C:/Path/outfile.xlsx')sheet = workbook.add_worksheet()cursor.execute("select * from TABLENAME")for r, row in enumerate(cursor.fetchall()):         for c, col in enumerate(row):                sheet.write(r, c, col)workbook.close()cursor.close()