这是可以做到在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。
这看起来像我需要开始,我将不得不进一步调查,但非常感谢您的帮助 – Trent