问题
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.
Does someone know a quick, elegant solution that generates a real Excel file? Like a small shell script or the like?
I want this to be done either on my Linux box (Debian 5.0 Lenny) or on Windows (XP or higher).
回答1:
You could install the PostgreSQL ODBC driver on the Windows machine, and then connect Excel to the database like explained in this blog post (except using ODBC rather than 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).
EDIT (thanks @Tometzky): The best solution is to use the PostgreSQL ODBC driver to connect Microsoft Access to the database and from Access export to Excel.
回答2:
Apparently you can use Power Query Add-in and the .Net PostgreSQL Data Provider for importing PostgreSQL data into Excel 2010 or Excel 2013...
Download 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
回答3:
This is fairly easy.
Make this the first line of .asp page: <%response.ContentType="application/vnd.ms-excel"%>
Make the rest like any other HTML page with a table in it.
Use ASP to fill the table with data from the database.
The server will create an Excel spreadsheet for you.
来源:https://stackoverflow.com/questions/5509460/postgresql-query-to-excel-sheet