简体   繁体   English

Libre/Open/Collabra Office 中的 getScriptProvider 和 createScriptProvider

[英]getScriptProvider and createScriptProvider in Libre/Open/Collabra Office

If location="document" Then
    sp = ThisComponent.getScriptProvider()
Else
    mspf = CreateUNOService("com.sun.star.script.provider.MasterScriptProviderFactory")
    sp = mspf.createScriptProvider("")
End If

That's a fairly standard example from the documentation: there is an example here: https://help.libreoffice.org/7.1/en-US/text/sbasic/guide/basic_2_python.html , and it's been around for a while: there is a /6.4/ example at the same place.这是文档中的一个相当标准的示例:这里有一个示例: https ://help.libreoffice.org/7.1/en-US/text/sbasic/guide/basic_2_python.html,它已经存在了一段时间:那里是同一个地方的 /6.4/ 例子。

Any idea why it written like that, with getScriptProvider and createScriptProvider?知道为什么用 getScriptProvider 和 createScriptProvider 那样写吗? The construct suggest that in some circumstances you have to Create a script provider, because you can't Get an existing one.该构造表明在某些情况下您必须创建脚本提供程序,因为您无法获取现有脚本提供程序。 But in my checks, getScriptProvider also works for 'user' and 'share' (which are just different locations for finding scripts).但在我的检查中,getScriptProvider 也适用于“用户”和“共享”(它们只是用于查找脚本的不同位置)。

It's not important to me, since I am only using location="document", but has anyone ever documented a situation where getScriptProvider fails?这对我来说并不重要,因为我只使用 location="document",但是有没有人记录过 getScriptProvider 失败的情况?

Look again at the line you're asking about.再看看你问的那一行。

sp = ThisComponent.getScriptProvider()

In some cases, you may not have a component to work with, for example, if the current document was (or will be) closed.在某些情况下,您可能没有要使用的组件,例如,如果当前文档已经(或将要)关闭。 So, get a script provider from the MasterScriptProviderFactory instead.因此,改为从 MasterScriptProviderFactory 获取脚本提供程序。

The source of the script provider determines which code can be run.脚本提供者的来源决定了哪些代码可以运行。 If the code is in a different document, then get the script provider from that one instead, especially if the function has the same name in different documents.如果代码在不同的文档中,则从该文档中获取脚本提供程序,尤其是当函数在不同的文档中具有相同的名称时。

One good thing about user and share is that they are available no matter where the script provider comes from. usershare的一个好处是无论脚本提供者来自哪里,它们都可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM