简体   繁体   English

将数据从 Oracle SQL Developer 导出到 Excel .xlsx

[英]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.我有一个小项目,需要将 Oracle SQL Developer 中的数据导出到 Excel(使用命令而不是 SLQ Developer 中的工具),然后创建一个图表。 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使用“假脱机”我可以导出到 csv 很好(但不能在 csv 中制作图形)但是当我尝试导出到 xlsx 时它会破坏整个 excel 表说

"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.这是我在 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?有什么方法可以阻止数据损坏,还是有其他方法可以将数据导出到 .xlsx 文件?

Nooooooo.呜呜呜。

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

then open the file in excel.然后用excel打开文件。

OR

Run your query interactively.以交互方式运行您的查询。

Right click on the grid, Export > XLSX.右键单击网格,导出 > 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. Spool 只将查询输出写入文件,它不会查看文件扩展名并找出此时如何写入输出。

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.使用“help set sqlformat”获取帮助。

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嗨,我知道导出的 sql 开发人员正在使用 sqlplus(代码相同),所以也许还有其他方法,但这应该足够了

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 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无论如何有解决方法 - 您可以生成 .CSV 文件,然后在 excel 中打开它并另存为 .xlsx 文件

I was also facing the same problem then applied below code and it exported successfully..我也遇到了同样的问题,然后在下面的代码中应用并成功导出..

import xlsxwriter
from xlsxwriter import Workbook
import cx_Oracle
import datetime
from datetime import date

dsn_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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Oracle SQL Developer导出数据? - How to export data with Oracle SQL Developer? Oracle sql 开发商| 从查询导出到表 - Oracle sql developer| export from query to a table Oracle Sql Developer导出速度慢 - Oracle Sql Developer export slow 导入.xlsx到Oracle SQL Developer错误 - Import .xlsx to oracle sql developer error 在 ADF 中工作我需要将数据从 sql 源导出到 Excel 目标,有没有办法在 ADF 中使用 Excel(.xlsx)作为目标? 笔记本? - Am working in ADF i need to export data from sql source to Excel destination, Is there way to use Excel(.xlsx) as destination in ADF ? Notebook? 如何从Oracle SQL Developer查询结果中批量导出每个表中的仅10行以分隔Excel文件 - How to batch export only 10 rows from Oracle SQL developer query results for each table to separate excel files 如何将 excel 电子表格中的大量数据插入 Oracle SQL 开发人员 - How to insert large amounts of data from excel spreadsheet into Oracle SQL Developer 将数据从Oracle导出到Excel-性能问题 - Export Data From Oracle to Excel - Performance issue 将 SQL 开发人员的多个表导出到单个 excel - Export multiple tables from SQL developer into a single excel Oracle SQL Developer 导出问题:目标不可写 - Oracle SQL Developer Export Issue: Target not writable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM