From fbbbb4dedd4e42ed16056ba9c98a829601f61833 Mon Sep 17 00:00:00 2001 From: Rafael Lima Date: Mon, 25 Jul 2022 21:33:42 +0200 Subject: Improve description of how to invoke Documents and Calc SF services Change-Id: Id9b9cc379bd838bdbae882554c8320f30595453e Reviewed-on: https://gerrit.libreoffice.org/c/help/+/137416 Tested-by: Jenkins Tested-by: Jean-Pierre Ledure Reviewed-by: Rafael Lima --- source/text/sbasic/shared/03/sf_calc.xhp | 11 ++++++++++- source/text/sbasic/shared/03/sf_document.xhp | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'source') diff --git a/source/text/sbasic/shared/03/sf_calc.xhp b/source/text/sbasic/shared/03/sf_calc.xhp index 2da2d254fa..8b143da7ff 100644 --- a/source/text/sbasic/shared/03/sf_calc.xhp +++ b/source/text/sbasic/shared/03/sf_calc.xhp @@ -62,12 +62,17 @@ Set oDoc = ui.OpenDocument("C:\Documents\MyFile.ods") - It is also possible to instantiate the Calc service using the CreateScriptService method: + It is also possible to instantiate the Calc service specifying a window name for the CreateScriptService method: Dim oDoc As Object Set oDoc = CreateScriptService("SFDocuments.Calc", "MyFile.ods") In the example above, "MyFile.ods" is the name of an open document window. If this argument is not provided, the active window is considered. + It is also possible to invoke the Calc service using the document referenced by ThisComponent. This is specially useful when running a macro from within the Basic IDE. + + Dim oDoc As Object + Set oDoc = CreateScriptService("Calc", ThisComponent) + It is recommended to free resources after use: Set oDoc = oDoc.Dispose() @@ -88,6 +93,10 @@ myDoc = CreateScriptService("SFDocuments.Calc", "MyFile.ods") myDoc.Dispose() + + bas = CreateScriptService("Basic") + myDoc = CreateScriptService("Calc", bas.ThisComponent) + The use of the prefix "SFDocuments." while calling the service is optional.

Definitions

diff --git a/source/text/sbasic/shared/03/sf_document.xhp b/source/text/sbasic/shared/03/sf_document.xhp index f0c0ee7c58..6a2e0129df 100644 --- a/source/text/sbasic/shared/03/sf_document.xhp +++ b/source/text/sbasic/shared/03/sf_document.xhp @@ -58,11 +58,16 @@ Set oDocA = ui.CreateDocument("Calc") Set oDocB = ui.OpenDocument("C:\Documents\MyFile.odt")
- Directly if the document is already open. + Using a window name if the document is already open. Dim oDoc As Object Set oDoc = CreateScriptService("SFDocuments.Document", "Untitled 1") 'Default = ActiveWindow + Using the document referenced by ThisComponent. This is specially useful when running a macro from within the Basic IDE. + + Dim oDoc As Object + Set oDoc = CreateScriptService("Document", ThisComponent) + From a macro triggered by a document event. Sub RunEvent(ByRef poEvent As Object) @@ -90,6 +95,10 @@ doc = CreateScriptService("SFDocuments.Document", "Untitled 1") + + + bas = CreateScriptService("Basic") + doc = CreateScriptService("Document", bas.ThisComponent) def RunEvent(event) -- cgit