简体   繁体   English

是否可以将Excel工作表导入数据库中的表?

[英]Is it possible to import an excel sheet as a table in the database?

This is the first time that I am attempting this, and I don't know if it is possible. 这是我第一次尝试这个,我不知道是否可能。 I am trying to develop an application that allows me to upload an excel file directly into a database. 我正在尝试开发一个允许我将excel文件直接上传到数据库的应用程序。

Is it possible to upload the excel data without first converting the excel sheet to the CSV format? 是否可以上传excel数据而无需先将Excel工作表转换为CSV格式? The database table contains fields and columns with the same names as the excel file. 数据库表包含与excel文件同名的字段和列。

Does anyone know of a tool which can do this for me? 有谁知道一个可以为我做这个的工具?

it is certainly possible. 这当然是可能的。 You might be interested in the JBoss Teiid project , which enables accessing Excel spreadsheet like it was a table. 您可能对JBoss Teiid项目感兴趣,该项目可以访问Excel电子表格,就像它是一个表格一样。

Given that, you can then easily fill all the values from a "virtual" table formed from the spreadsheet (let's call it excelTable) into another table (let's call it targetTable): 鉴于此,您可以轻松地将电子表格形成的“虚拟”表中的所有值(我们称之为excelTable)填充到另一个表中(让我们称之为targetTable):

INSERT INTO targetTable(column1,...) SELECT column1,... FROM excelTable;

The project is open-source so if its usage doesn't fit your needs, you can always look at the sources and maybe get an inspiration, how you can do such things. 该项目是开源的,所以如果它的使用不符合您的需求,您可以随时查看来源并获得灵感,如何做这些事情。

Best regards 最好的祝福

Jan 一月

For Oracle, the easiest way is to use sqlldr for bulk load. 对于Oracle,最简单的方法是使用sqlldr进行批量加载。

So you need an application that will parse the xls/xlsx and write a data file for sqlldr (can be csv , in fact any delimited text file). 因此,您需要一个将解析xls/xlsx并为sqlldr写入数据文件的应用程序(可以是csv ,实际上是任何分隔的文本文件)。

If you really don't want to convert the file you could parse it and insert each row at a time, but this method is very slow when dealing with a lot of data. 如果你真的不想转换文件,你可以解析它并一次插入每一行,但这种方法在处理大量数据时非常慢。

Sqlldr FAQ Sqlldr FAQ

EDIT : Equivalent tool for sqlserver is called BCP 编辑sqlserver等效工具称为BCP

BCP Tool BCP工具

And of course, you can use the tools withouth any software attached, running them via command lines once you have the data and/or control files ready. 当然,您可以在没有任何附加软件的情况下使用这些工具,一旦准备好数据和/或控制文件,就可以通过命令行运行它们。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM