LibreOffice Calc执行PostgreSQL函数

我目前正在使用Microsoft Excel来执行SQL Server数据库上的存储过程,它工作正常。

如果有人感兴趣,这里有非常好的说明http://datapigtechnologies.com/blog/index.php/running-a-sql-stored-procedure-from-excel-with-dynamic-parameters/

我想知道是否有可能用LibreOffice Calc和PostgreSQL做这样的事情。

我知道LibreOffice支持PostgreSQL连接,因为您可以创buildPostgreSQL odb文件,但是我想知道是否可以像Excel一样执行Stored Porcedures / Functions

在LibreOffice Calc中可以做类似的事情,而不是用各种菜单设置数据库连接,所有事情都是用macros代码完成的。

以下为我使用这个MySQL存储过程 :

Sub RunStoredProc Dim oParms(1) as new com.sun.star.beans.PropertyValue oParms(0).Name = "user" oParms(0).Value = "root" oParms(1).Name = "password" oParms(1).Value = "password" oManager = CreateUnoService("com.sun.star.sdbc.DriverManager") sURL = "sdbc:mysql:jdbc:localhost:3306/world" oConnection = oManager.getConnectionWithInfo(sURL, oParms()) sFormat = "Europe" oStmt = oConnection.prepareCall("CALL country_hos(?)") oStmt.setString(1, sFormat) oResult = oStmt.executeQuery() sResult = "" If Not IsNull(oResult) Then While oResult.Next() sResult = sResult & oResult.getString(1) & CHR(10) Wend End If MsgBox "Result: " & sFormat & " = " & CHR(10) & sResult oStmt.close() End Sub 

该代码是从https://forum.openoffice.org/en/forum/viewtopic.php?f=21&t=41149改编的。

要完成代码,请将其修改为将结果放入电子表格中,而不是在消息框中显示它们。 同时从下拉框中读取选定的值,而不是硬编码sFormat的值。

注意:一些在线信息build议使用中间的.odb文件。 这将涉及更多的菜单,而不是在macros中做所有事情。 这适用于表和查询,但显然不适用于存储过程,除非在这里提到HSQLDB。