是否可以从 Excel 中的 VBA 进行类似 SELECT
的查询,以便我可以从 Excel 查询 PostgreSQL 数据库?
如果可能,请向我解释如何连接到数据库。我在 Google 中查找,但没有找到任何结果。
最佳答案
在 PostgreSQL 中创建一个表或 View 来描述您想要的数据。
使用来自 VBA 的 ODBC 或 ADO 连接连接到 PostgreSQL。如果使用 ODBC,您需要通过 odbcad32.exe
创建 DSN,然后在 VB 中使用 DSN,直接连接并不容易。
参见:
- Using ADO in VBA to connect to PostgreSQL
- PostgreSQL Query to Excel Sheet
- http://jackdebear.blogspot.com.au/2011/11/connecting-to-postgres-from-excel.html
- Enabling import/export flows between a remote postgres database and excel workbooks
- Does ADO work with ODBC drivers or only OLE DB providers?
- How to put query results into a datatable with Excel VBA and ADO?
Better written eample that uses Oracle , 但原理是相同的 - ODBC/ADO。
关于excel - 通过 VBA 将 Excel 连接到 PostgreSQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13230456/