2017-03-16 89 views
1

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

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

我想知道是否有可能做这样的事与LibreOffice的计算器和PostgreSQL。

我知道的LibreOffice支持PostgreSQL的连接,你可以创建一个PostgreSQL ODB文件,但我不知道是否有可能以类似的方式来执行存储Porcedures /功能到Excel中是如何做的

回答

1

这是可以做到在LibreOffice Calc中类似的东西,但不是用各种菜单设置数据库连接,而是用宏代码完成一切。

下工作我使用this MySQL stored procedure为:

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的值进行硬编码。

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

+0

这看起来像我需要开始,我将不得不进一步调查,但非常感谢您的帮助 – Trent