有人能帮我解决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运行--无论如何。
My LibreOffice版本:版本: 7.1.3.2 (x64) / LibreOffice社区构建ID: 47f78053abe362b9384784d31a6e56f8511eb1cpu线程: 8;OS: Windows10.0Build 19042;UI呈现: Skia/Raster;VCL: win Locale: cs-CZ (cs_CZ);UI: cs-CZ Calc: CL
谢谢你的帮助。
发布于 2021-06-25 17:25:42
这条路很管用。
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有关。
https://stackoverflow.com/questions/68126953
复制相似问题