将 Excel 电子表格导入 PostgreSQL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1645286/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 23:53:49  来源:igfitidea点击:

Import Excel spreadsheet into PostgreSQL

excelpostgresqlimport

提问by Matt Haley

I need to be able to import an Excel spreadsheet into a PostgreSQL database. The goal is for use with a Rails application. I have looked at the Roo gemand it takes 16 seconds to convert a 2000 line XLS file to CSV which is unacceptable. So I was wondering if I could just short-circuit the Rails application and import directly into PostgreSQL.

我需要能够将 Excel 电子表格导入 PostgreSQL 数据库。目标是与 Rails 应用程序一起使用。我看过Roo gem,将 2000 行 XLS 文件转换为 CSV 需要 16 秒,这是不可接受的。所以我想知道我是否可以将 Rails 应用程序短路并直接导入到 PostgreSQL 中。

Is there a way to import data from an Excel spreadsheet directly into PostgreSQL?

有没有办法将 Excel 电子表格中的数据直接导入 PostgreSQL?

回答by Magnus Hagander

No, PostgreSQL does not read the XLS file format (nor the XLSX format). You can import from CSV, and in some cases from XML, but that's all (without external preprocessing).

不,PostgreSQL 不读取 XLS 文件格式(也不读取 XLSX 格式)。您可以从 CSV 导入,在某些情况下从 XML 导入,但仅此而已(无需外部预处理)。

However, if you actually have access to Excel, you can always just export it in an open format (preferrably CSV) directly from inside Excel.

但是,如果您确实可以访问 Excel,则始终可以直接从 Excel 内部以开放格式(最好是 CSV)导出它。