SQL PostgreSQL 查询到 Excel 表格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5509460/
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
PostgreSQL Query to Excel Sheet
提问by Daniel
I need to export some data from PostgreSQL to Excel (quick customer wish), and the last time Excel had serious problems opening or importing my COPYd csv files (line endings, utf-8 encoding, etc), and it took me an hour at best.
我需要将一些数据从 PostgreSQL 导出到 Excel(客户的快速愿望),上次 Excel 在打开或导入我的 COPYd csv 文件(行尾、utf-8 编码等)时遇到严重问题,我花了一个小时最好的事物。
Does someone know a quick, elegant solution that generates a real Excel file? Like a small shell script or the like?
有人知道生成真正的 Excel 文件的快速、优雅的解决方案吗?像一个小的shell脚本之类的?
I want this to be done either on my Linux box (Debian 5.0 Lenny) or on Windows (XP or higher).
我希望这可以在我的 Linux 机器(Debian 5.0 Lenny)或 Windows(XP 或更高版本)上完成。
采纳答案by StackExchange saddens dancek
You could install the PostgreSQL ODBC driveron the Windows machine, and then connect Excel to the database like explained in this blog post(except using ODBC rather than OLEDB).
您可以在 Windows 机器上安装PostgreSQL ODBC 驱动程序,然后按照这篇博文中的说明将 Excel 连接到数据库(除了使用 ODBC 而不是 OLEDB)。
I haven't tested this. I'm not really sure if this makes it any easier than exporting CSV and fixing it (given what Excel is like).
我没有测试过这个。我不确定这是否比导出 CSV 和修复它更容易(考虑到 Excel 是什么样的)。
EDIT (thanks @Tometzky): The best solutionis to use the PostgreSQL ODBC driver to connect Microsoft Access to the database and from Access export to Excel.
编辑(感谢@Tometzky):最好的解决方案是使用 PostgreSQL ODBC 驱动程序将 Microsoft Access 连接到数据库,并从 Access 导出到 Excel。
回答by Flatliner DOA
Apparently you can use Power Query Add-in and the .Net PostgreSQL Data Provider for importing PostgreSQL data into Excel 2010 or Excel 2013...
显然,您可以使用 Power Query 插件和 .Net PostgreSQL 数据提供程序将 PostgreSQL 数据导入 Excel 2010 或 Excel 2013 ...
Download http://www.microsoft.com/en-au/download/details.aspx?id=39379
下载 http://www.microsoft.com/en-au/download/details.aspx?id=39379
How to for using PostgreSQL: https://support.office.com/en-ie/article/Connect-to-a-PostgreSQL-database-bf941e52-066f-4911-a41f-2493c39e69e4
如何使用 PostgreSQL:https: //support.office.com/en-ie/article/Connect-to-a-PostgreSQL-database-bf941e52-066f-4911-a41f-2493c39e69e4
回答by Ken
This is fairly easy.
这相当容易。
Make this the first line of .asp page: <%response.ContentType="application/vnd.ms-excel"%>
将此作为 .asp 页面的第一行:<%response.ContentType="application/vnd.ms-excel"%>
Make the rest like any other HTML page with a table in it.
使其余部分像任何其他带有表格的 HTML 页面一样。
Use ASP to fill the table with data from the database.
使用 ASP 用数据库中的数据填充表。
The server will create an Excel spreadsheet for you.
服务器将为您创建一个 Excel 电子表格。