问题描述
有人可以帮我解决 Hex2Bin 和 Bin2Hex 函数的问题吗? 首先,我试图进行转换 Hex2Bin。我想从宏调用 AddIn 函数,所以我调用了 createUNOservice:
Function fcHex2Bin(arg as variant,NumberOfBits As integer) as string
Dim oService as Object
oService = createUNOService("com.sun.star.sheet.addin.Analysis")
sArg = cStr(arg)
fcHex2Bin = oService.getHex2Bin(sArg,NumberOfBits)
End Function
但始终以“未设置对象变量”等错误消息结束。我已经不知道为什么了。
我的最终目标是让 Calc 的所有函数在宏中运行,但此时我很高兴有两个函数 Hex2Bin 和 Bin2Hex 运行 - 无论如何。
我的 LibreOffice 版本: 版本:7.1.3.2 (x64) / LibreOffice 社区 内部版本 ID:47f78053abe362b9384784d31a6e56f8511eb1c1 cpu线程:8;操作系统:Windows 10.0 Build 19042; UI 渲染:Skia/Raster; VCL:赢 语言环境:cs-CZ (cs_CZ);用户界面:cs-CZ 计算:CL
感谢您的帮助。
解决方法
这种方式有效。
Function fcHex2Bin(aNum As String,rPlaces As Any) As String
Dim oFunc As Object
oFunc = CreateUnoService("com.sun.star.sheet.FunctionAccess")
Dim aArgs(0 to 1) As Variant
aArgs(0) = aNum
aArgs(1) = rPlaces
fcHex2Bin = oFunc.callFunction("com.sun.star.sheet.addin.Analysis.getHex2Bin",aArgs())
End Function
至于为什么其他方式不起作用,许多分析函数需要一个隐藏的 XPropertySet
对象作为第一个参数。以下代码会生成信息性错误消息:
REM IllegalArgumentException: expected 3 arguments,got 1
sResult = oService.getHex2Bin(ThisComponent.getPropertySetInfo())
REM IllegalArgumentException: arg no. 0 expected: "com.sun.star.beans.XPropertySet"
sResult = oService.getHex2Bin(ThisComponent.getPropertySetInfo(),"2",4)
但是,我尝试从 Calc 电子表格中传递 ThisComponent.getPropertySetInfo().getProperties()
并且它仍然不起作用,所以我不确定这样做需要什么。
https://help.libreoffice.org/latest/he/text/sbasic/shared/calc_functions.html 上的文档并没有真正解释这一点。您可以提交有关缺失文档的错误报告,可能与 https://bugs.documentfoundation.org/show_bug.cgi?id=134032 相关。