summaryrefslogtreecommitdiff
path: root/wizards/source/sfdocuments
diff options
context:
space:
mode:
authorJean-Pierre Ledure <jp@ledure.be>2022-11-01 17:27:21 +0100
committerJean-Pierre Ledure <jp@ledure.be>2022-11-02 11:26:46 +0100
commit985c77b570807dcc558ccff4a51430fe489b68fd (patch)
treea359700248abe601efb1c5341af1542ef9bc689b /wizards/source/sfdocuments
parent4f88a1d624a97f53b58d3cdf36b2f5cfc237da59 (diff)
ScriptForge = (SFDatabases) New Datasheet service
A datasheet is the visual representation of tabular data produced by a database. In the user interface of LibreOffice it is the result of the opening of a table or a query. In this case the concerned Base document must be open. In the context of ScriptForge, a datasheet may be opened automatically by script code : - either by reproducing the behaviour of the user interface - or at any moment. In this case the Base document does not need to be open. Additionally, any SELECT SQL statement may define the datasheet display. The proposed API allows for either datasheets (opened manually of by code) in particular to know which cell is selected and its content. Properties: ColumnHeaders CurrentColumn CurrentRow LastRow Source SourceType XComponent XControlModel XTabControllerModel Methods Activate ApplyFilter CloseDatasheet GetValue GetText GoToCell OrderBy The Base and Database services are enriched with the OpenTable OpenQuery methods. The Database service gets also a new OpenSql method. The whole set of properties and methods is available both for Basic and Python scripts. This new service requires a new help page dedicated to this service, as well as an update of the pages about the Base and Database services. Change-Id: Ib409ce74d95de78f2792ba53e7ae554eab0867ab Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142118 Tested-by: Jenkins Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Diffstat (limited to 'wizards/source/sfdocuments')
-rw-r--r--wizards/source/sfdocuments/SF_Base.xba107
-rw-r--r--wizards/source/sfdocuments/SF_Calc.xba50
-rw-r--r--wizards/source/sfdocuments/SF_Document.xba4
3 files changed, 134 insertions, 27 deletions
diff --git a/wizards/source/sfdocuments/SF_Base.xba b/wizards/source/sfdocuments/SF_Base.xba
index 1e6395dbfa2c..81afacc7bbda 100644
--- a/wizards/source/sfdocuments/SF_Base.xba
+++ b/wizards/source/sfdocuments/SF_Base.xba
@@ -459,7 +459,7 @@ Public Function OpenFormDocument(Optional ByVal FormDocument As Variant _
&apos;&apos;&apos; Open the FormDocument given by its hierarchical name either in normal or in design mode
&apos;&apos;&apos; If the form document is already open, the form document is made active without changing its mode
&apos;&apos;&apos; Args:
-&apos;&apos;&apos; FormDocument: a valid document form name as a case-sensitive string
+&apos;&apos;&apos; FormDocument: a valid form document name as a case-sensitive string
&apos;&apos;&apos; DesignMode: when True the form document is opened in design mode (Default = False)
&apos;&apos;&apos; Returns:
&apos;&apos;&apos; True if the form document could be opened, otherwise False
@@ -510,6 +510,111 @@ Catch:
End Function &apos; SFDocuments.SF_Base.OpenFormDocument
REM -----------------------------------------------------------------------------
+Public Function OpenQuery(Optional ByVal QueryName As Variant _
+ , Optional ByVal DesignMode As Variant _
+ ) As Object
+&apos;&apos;&apos; Open the query given by its name either in normal or in design mode
+&apos;&apos;&apos; If the query is already open, the query datasheet is made active without changing its mode
+&apos;&apos;&apos; If still open, the datasheet will be closed together with the actual Base document.
+&apos;&apos;&apos; Args:
+&apos;&apos;&apos; QueryName: a valid Query name as a case-sensitive string
+&apos;&apos;&apos; DesignMode: when True the query is opened in design mode (Default = False)
+&apos;&apos;&apos; Returns:
+&apos;&apos;&apos; A Datasheet class instance if the query could be opened and DesignMode = False, otherwise False
+&apos;&apos;&apos; Exceptions:
+&apos;&apos;&apos; Query name is invalid
+&apos;&apos;&apos; Example:
+&apos;&apos;&apos; oDoc.OpenQuery(&quot;myQuery&quot;, DesignMode := False)
+
+Dim oOpen As Object &apos; Return value
+Dim vQueries As Variant &apos; Array of query names
+Dim oNewQuery As Object &apos; Output of loadComponent()
+Const cstThisSub = &quot;SFDocuments.Base.OpenQuery&quot;
+Const cstSubArgs = &quot;QueryName, [DesignMode=False]&quot;
+
+ If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
+ Set oOpen = Nothing
+
+Check:
+ If IsMissing(DesignMode) Or IsEmpty(DesignMode) Then DesignMode = False
+ vQueries = GetDatabase().Queries &apos; Includes _IsStillAlive()
+ If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
+ If Not ScriptForge.SF_Utils._Validate(QueryName, &quot;QueryName&quot;, V_STRING, vQueries) Then GoTo Finally
+ If Not ScriptForge.SF_Utils._Validate(DesignMode, &quot;DesignMode&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
+ End If
+
+Try:
+ With _Component.CurrentController
+ &apos; The connection may have been done previously by a user commmand. If not, do it now.
+ If Not .IsConnected Then .connect()
+ &apos; loadComponent activates the query component when already loaded
+ Set oNewQuery = .loadComponent(com.sun.star.sdb.application.DatabaseObject.QUERY, QueryName, DesignMode)
+ End With
+ &apos; When design mode, the method returns Nothing
+ If Not DesignMode Then Set oOpen = ScriptForge.SF_Services.CreateScriptService(&quot;SFDatabases.Datasheet&quot;, [Me], oNewQuery)
+
+Finally:
+ Set OpenQuery = oOpen
+ ScriptForge.SF_Utils._ExitFunction(cstThisSub)
+ Exit Function
+Catch:
+ GoTo Finally
+End Function &apos; SFDocuments.SF_Base.OpenQuery
+
+REM -----------------------------------------------------------------------------
+Public Function OpenTable(Optional ByVal TableName As Variant _
+ , Optional ByVal DesignMode As Variant _
+ ) As Object
+&apos;&apos;&apos; Open the table given by its name either in normal or in design mode
+&apos;&apos;&apos; If the table is already open, the table datasheet is made active without changing its mode
+&apos;&apos;&apos; If still open, the datasheet will be closed together with the actual Base document.
+&apos;&apos;&apos; Args:
+&apos;&apos;&apos; TableName: a valid table name as a case-sensitive string
+&apos;&apos;&apos; DesignMode: when True the table is opened in design mode (Default = False)
+&apos;&apos;&apos; Returns:
+&apos;&apos;&apos; A Datasheet class instance if the table could be opened or was already open, and DesignMode = False.
+&apos;&apos;&apos; Otherwise Nothing
+&apos;&apos;&apos; Exceptions:
+&apos;&apos;&apos; Table name is invalid
+&apos;&apos;&apos; Example:
+&apos;&apos;&apos; oDoc.OpenTable(&quot;myTable&quot;, DesignMode := False)
+
+Dim oOpen As Object &apos; Return value
+Dim vTables As Variant &apos; Array of table names
+Dim oNewTable As Object &apos; Output of loadComponent()
+Const cstThisSub = &quot;SFDocuments.Base.OpenTable&quot;
+Const cstSubArgs = &quot;TableName, [DesignMode=False]&quot;
+
+ If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
+ Set oOpen = Nothing
+
+Check:
+ If IsMissing(DesignMode) Or IsEmpty(DesignMode) Then DesignMode = False
+ vTables = GetDatabase().Tables
+ If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
+ If Not ScriptForge.SF_Utils._Validate(TableName, &quot;TableName&quot;, V_STRING, vTables) Then GoTo Finally
+ If Not ScriptForge.SF_Utils._Validate(DesignMode, &quot;DesignMode&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
+ End If
+
+Try:
+ With _Component.CurrentController
+ &apos; The connection may have been done previously by a user commmand. If not, do it now.
+ If Not .IsConnected Then .connect()
+ &apos; loadComponent activates the table component when already loaded
+ Set oNewTable = .loadComponent(com.sun.star.sdb.application.DatabaseObject.TABLE, TableName, DesignMode)
+ End With
+ &apos; When design mode, the method returns Nothing
+ If Not DesignMode Then Set oOpen = ScriptForge.SF_Services.CreateScriptService(&quot;SFDatabases.Datasheet&quot;, [Me], oNewTable)
+
+Finally:
+ Set OpenTable = oOpen
+ ScriptForge.SF_Utils._ExitFunction(cstThisSub)
+ Exit Function
+Catch:
+ GoTo Finally
+End Function &apos; SFDocuments.SF_Base.OpenTable
+
+REM -----------------------------------------------------------------------------
Public Function PrintOut(Optional ByVal FormDocument As Variant _
, Optional ByVal Pages As Variant _
, Optional ByVal Copies As Variant _
diff --git a/wizards/source/sfdocuments/SF_Calc.xba b/wizards/source/sfdocuments/SF_Calc.xba
index e32dab652166..0733be07eb6a 100644
--- a/wizards/source/sfdocuments/SF_Calc.xba
+++ b/wizards/source/sfdocuments/SF_Calc.xba
@@ -401,7 +401,7 @@ Finally:
Exit Function
Catch:
GoTo Finally
-End Function &apos; SF_Documents.SF_Calc.A1Style
+End Function &apos; SFDocuments.SF_Calc.A1Style
REM -----------------------------------------------------------------------------
Public Function Activate(Optional ByVal SheetName As Variant) As Boolean
@@ -560,7 +560,7 @@ Public Sub ClearAll(Optional ByVal Range As Variant _
_ClearRange(&quot;All&quot;, Range, FilterFormula, FilterScope)
-End Sub &apos; SF_Documents.SF_Calc.ClearAll
+End Sub &apos; SFDocuments.SF_Calc.ClearAll
REM -----------------------------------------------------------------------------
Public Sub ClearFormats(Optional ByVal Range As Variant _
@@ -580,7 +580,7 @@ Public Sub ClearFormats(Optional ByVal Range As Variant _
_ClearRange(&quot;Formats&quot;, Range, FilterFormula, FilterScope)
-End Sub &apos; SF_Documents.SF_Calc.ClearFormats
+End Sub &apos; SFDocuments.SF_Calc.ClearFormats
REM -----------------------------------------------------------------------------
Public Sub ClearValues(Optional ByVal Range As Variant _
@@ -600,7 +600,7 @@ Public Sub ClearValues(Optional ByVal Range As Variant _
_ClearRange(&quot;Values&quot;, Range, FilterFormula, FilterScope)
-End Sub &apos; SF_Documents.SF_Calc.ClearValues
+End Sub &apos; SFDocuments.SF_Calc.ClearValues
REM -----------------------------------------------------------------------------
Public Function CompactLeft(Optional ByVal Range As Variant _
@@ -1424,7 +1424,7 @@ Try:
Finally:
Exit Function
-End Function &apos; SF_Documents.SF_Calc.DAvg
+End Function &apos; SFDocuments.SF_Calc.DAvg
REM -----------------------------------------------------------------------------
Public Function DCount(Optional ByVal Range As Variant) As Long
@@ -1441,7 +1441,7 @@ Try:
Finally:
Exit Function
-End Function &apos; SF_Documents.SF_Calc.DCount
+End Function &apos; SFDocuments.SF_Calc.DCount
REM -----------------------------------------------------------------------------
Public Function DMax(Optional ByVal Range As Variant) As Double
@@ -1458,7 +1458,7 @@ Try:
Finally:
Exit Function
-End Function &apos; SF_Documents.SF_Calc.DMax
+End Function &apos; SFDocuments.SF_Calc.DMax
REM -----------------------------------------------------------------------------
Public Function DMin(Optional ByVal Range As Variant) As Double
@@ -1475,7 +1475,7 @@ Try:
Finally:
Exit Function
-End Function &apos; SF_Documents.SF_Calc.DMin
+End Function &apos; SFDocuments.SF_Calc.DMin
REM -----------------------------------------------------------------------------
Public Function DSum(Optional ByVal Range As Variant) As Double
@@ -1492,7 +1492,7 @@ Try:
Finally:
Exit Function
-End Function &apos; SF_Documents.SF_Calc.DSum
+End Function &apos; SFDocuments.SF_Calc.DSum
REM -----------------------------------------------------------------------------
Public Function ExportRangeToFile(Optional ByVal Range As Variant _
@@ -1754,7 +1754,7 @@ Finally:
Exit Function
Catch:
GoTo Finally
-End Function &apos; SF_Documents.SF_Calc.GetFormula
+End Function &apos; SFDocuments.SF_Calc.GetFormula
REM -----------------------------------------------------------------------------
Public Function GetProperty(Optional ByVal PropertyName As Variant _
@@ -1839,7 +1839,7 @@ Finally:
Exit Function
Catch:
GoTo Finally
-End Function &apos; SF_Documents.SF_Calc.GetValue
+End Function &apos; SFDocuments.SF_Calc.GetValue
REM -----------------------------------------------------------------------------
Public Function ImportFromCSVFile(Optional ByVal FileName As Variant _
@@ -2300,7 +2300,7 @@ Finally:
Exit Function
Catch:
GoTo Finally
-End Function &apos; SF_Documents.SF_Calc.Offset
+End Function &apos; SFDocuments.SF_Calc.Offset
REM -----------------------------------------------------------------------------
Public Function OpenRangeSelector(Optional ByVal Title As Variant _
@@ -2381,7 +2381,7 @@ Finally:
Exit Function
Catch:
GoTo Finally
-End Function &apos; SF_Documents.SF_Calc.OpenRangeSelector
+End Function &apos; SFDocuments.SF_Calc.OpenRangeSelector
REM -----------------------------------------------------------------------------
Public Function Printf(Optional ByVal InputStr As Variant _
@@ -2478,7 +2478,7 @@ Finally:
Exit Function
Catch:
GoTo Finally
-End Function &apos; SF_Documents.SF_Calc.Printf
+End Function &apos; SFDocuments.SF_Calc.Printf
REM -----------------------------------------------------------------------------
Public Function PrintOut(Optional ByVal SheetName As Variant _
@@ -2711,7 +2711,7 @@ Finally:
Exit Function
Catch:
GoTo Finally
-End Function &apos; SF_Documents.SF_Calc.SetArray
+End Function &apos; SFDocuments.SF_Calc.SetArray
REM -----------------------------------------------------------------------------
Public Function SetCellStyle(Optional ByVal TargetRange As Variant _
@@ -2789,7 +2789,7 @@ Finally:
Exit Function
Catch:
GoTo Finally
-End Function &apos; SF_Documents.SF_Calc.SetCellStyle
+End Function &apos; SFDocuments.SF_Calc.SetCellStyle
REM -----------------------------------------------------------------------------
Public Function SetFormula(Optional ByVal TargetRange As Variant _
@@ -2858,7 +2858,7 @@ Finally:
Exit Function
Catch:
GoTo Finally
-End Function &apos; SF_Documents.SF_Calc.SetFormula
+End Function &apos; SFDocuments.SF_Calc.SetFormula
REM -----------------------------------------------------------------------------
Private Function SetProperty(Optional ByVal psProperty As String _
@@ -2966,7 +2966,7 @@ Finally:
Exit Function
Catch:
GoTo Finally
-End Function &apos; SF_Documents.SF_Calc.SetValue
+End Function &apos; SFDocuments.SF_Calc.SetValue
REM -----------------------------------------------------------------------------
Public Function ShiftDown(Optional ByVal Range As Variant _
@@ -3423,7 +3423,7 @@ Finally:
Exit Function
Catch:
GoTo Finally
-End Function &apos; SF_Documents.SF_Calc.SortRange
+End Function &apos; SFDocuments.SF_Calc.SortRange
REM ======================================================= SUPERCLASS PROPERTIES
@@ -3685,7 +3685,7 @@ Finally:
Exit Sub
Catch:
GoTo Finally
-End Sub &apos; SF_Documents.SF_Calc._ClearRange
+End Sub &apos; SFDocuments.SF_Calc._ClearRange
REM -----------------------------------------------------------------------------
Private Function _ComputeFilter(ByRef poRange As Object _
@@ -3853,7 +3853,7 @@ Try:
Finally:
_ConvertFromDataArray = vArray
-End Function &apos; SF_Documents.SF_Calc._ConvertFromDataArray
+End Function &apos; SFDocuments.SF_Calc._ConvertFromDataArray
REM -----------------------------------------------------------------------------
Private Function _ConvertToCellValue(ByVal pvItem As Variant) As Variant
@@ -3873,7 +3873,7 @@ Try:
Finally:
_ConvertToCellValue = vCell
Exit Function
-End Function &apos; SF_Documents.SF_Calc._ConvertToCellValue
+End Function &apos; SFDocuments.SF_Calc._ConvertToCellValue
REM -----------------------------------------------------------------------------
Private Function _ConvertToDataArray(ByRef pvArray As Variant _
@@ -3997,7 +3997,7 @@ Try:
Finally:
_ConvertToDataArray = vDataArray
Exit Function
-End Function &apos; SF_Documents.SF_Calc._ConvertToDataArray
+End Function &apos; SFDocuments.SF_Calc._ConvertToDataArray
REM -----------------------------------------------------------------------------
Private Function _DFunction(ByVal psFunction As String _
@@ -4043,7 +4043,7 @@ Finally:
Exit Function
Catch:
GoTo Finally
-End Function &apos; SF_Documents.SF_Calc._DFunction
+End Function &apos; SFDocuments.SF_Calc._DFunction
REM -----------------------------------------------------------------------------
Private Function _FileIdent() As String
@@ -4205,7 +4205,7 @@ CatchAddress:
, &quot;Rows&quot;, plRows, &quot;Columns&quot;, plColumns, &quot;Height&quot;, plHeight, &quot;Width&quot;, plWidth _
, &quot;Document&quot;, [_Super]._FileIdent())
GoTo Finally
-End Function &apos; SF_Documents.SF_Calc._Offset
+End Function &apos; SFDocuments.SF_Calc._Offset
REM -----------------------------------------------------------------------------
Private Function _ParseAddress(ByVal psAddress As String) As Object
diff --git a/wizards/source/sfdocuments/SF_Document.xba b/wizards/source/sfdocuments/SF_Document.xba
index 30508f2e87b1..e537b90e5da1 100644
--- a/wizards/source/sfdocuments/SF_Document.xba
+++ b/wizards/source/sfdocuments/SF_Document.xba
@@ -864,7 +864,9 @@ Check:
&apos; When called from a subclass (Calc, Writer, ..) the arguments are gathered into one single array item
vArgs = Args
If IsArray(Args) Then
- If UBound(Args) &gt;= 0 And IsArray(Args(0)) Then vArgs = Args(0)
+ If UBound(Args) &gt;= 0 Then
+ If IsArray(Args(0)) Then vArgs = Args(0)
+ End If
End If
If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
If Not _IsStillAlive() Then GoTo Finally