diff options
author | Jean-Pierre Ledure <jp@ledure.be> | 2021-06-22 15:50:06 +0200 |
---|---|---|
committer | Jean-Pierre Ledure <jp@ledure.be> | 2021-06-22 18:10:01 +0200 |
commit | 8467a8e0587011269e376a65a0e397e096a36cc5 (patch) | |
tree | 40eb769d3ee4f7d5dc0ba2e514c6dddbad521939 /wizards | |
parent | ce20614b630e50fbfcc82e4cd2f565b04dfb788e (diff) |
ScriptForge - (SF_UI) CreateBaseDocument() new CalcFileName argument
Syntax of CreateBaseDocument() becomes
FileName, [EmbeddedDatabase=HSQLDB|FIREBIRD|CALC],
[RegistrationName=""], [CalcFileName]
Only when EmbedddedDatabase = "CALC", the new argument CalcFileName
represents the file containing the tables as Calc sheets.
The file must exist or an error is raised.
Example:
Dim myBase As Object, myCalcBase As Object
Set myBase = ui.CreateBaseDocument("C:\Databases\MyBaseFile.odb", "FIREBIRD")
Set myCalcBase = ui.CreateBaseDocument("C:\Databases\MyCalcBaseFile.odb", _
"CALC", , "C:\Databases\MyCalcFile.ods")
Both Basic and Python are supported.
Change-Id: I9912b110dcec12fe451a47abb61ab143fb543b94
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117665
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Diffstat (limited to 'wizards')
-rw-r--r-- | wizards/source/scriptforge/SF_UI.xba | 36 | ||||
-rw-r--r-- | wizards/source/scriptforge/python/scriptforge.py | 5 |
2 files changed, 32 insertions, 9 deletions
diff --git a/wizards/source/scriptforge/SF_UI.xba b/wizards/source/scriptforge/SF_UI.xba index 07108c5fe438..4c9907ec39e3 100644 --- a/wizards/source/scriptforge/SF_UI.xba +++ b/wizards/source/scriptforge/SF_UI.xba @@ -42,6 +42,7 @@ Const DOCUMENTERROR = "DOCUMENTERROR" ' Requested document Const DOCUMENTCREATIONERROR = "DOCUMENTCREATIONERROR" ' Incoherent arguments, new document could not be created Const DOCUMENTOPENERROR = "DOCUMENTOPENERROR" ' Document could not be opened, check the arguments Const BASEDOCUMENTOPENERROR = "BASEDOCUMENTOPENERROR" ' Id. for Base document +Const UNKNOWNFILEERROR = "UNKNOWNFILEERROR" ' Calc datasource does not exist REM ============================================================= PRIVATE MEMBERS @@ -207,20 +208,27 @@ REM ---------------------------------------------------------------------------- Public Function CreateBaseDocument(Optional ByVal FileName As Variant _ , Optional ByVal EmbeddedDatabase As Variant _ , Optional ByVal RegistrationName As Variant _ + , Optional ByVal CalcFileName As Variant _ ) As Object ''' Create a new LibreOffice Base document embedding an empty database of the given type ''' Args: ''' FileName: Identifies the file to create. It must follow the SF_FileSystem.FileNaming notation ''' If the file already exists, it is overwritten without warning -''' EmbeddedDatabase: either "HSQLDB" (default) or "FIREBIRD" +''' EmbeddedDatabase: either "HSQLDB" (default) or "FIREBIRD" or "CALC" ''' RegistrationName: the name used to store the new database in the databases register ''' If "" (default), no registration takes place ''' If the name already exists it is overwritten without warning +''' CalcFileName: only when EmbedddedDatabase = "CALC", the name of the file containing the tables as Calc sheets +''' The name of the file must be given in SF_FileSystem.FileNaming notation +''' The file must exist ''' Returns: ''' A SFDocuments.SF_Document object or one of its subclasses +''' Exceptions +''' UNKNOWNFILEERROR Calc datasource does not exist ''' Examples: -''' Dim myBase As Object +''' Dim myBase As Object, myCalcBase As Object ''' Set myBase = ui.CreateBaseDocument("C:\Databases\MyBaseFile.odb", "FIREBIRD") +''' Set myCalcBase = ui.CreateBaseDocument("C:\Databases\MyCalcBaseFile.odb", "CALC", , "C:\Databases\MyCalcFile.ods") Dim oCreate As Variant ' Return value Dim oDBContext As Object ' com.sun.star.sdb.DatabaseContext @@ -230,27 +238,38 @@ Dim sFileName As String ' Alias of FileName Dim FSO As Object ' Alias for FileSystem service Const cstDocType = "private:factory/s" Const cstThisSub = "UI.CreateBaseDocument" -Const cstSubArgs = "FileName, [EmbeddedDatabase=""HSQLDB""|""FIREBIRD""], [RegistrationName=""""]" +Const cstSubArgs = "FileName, [EmbeddedDatabase=""HSQLDB""|""FIREBIRD""|""CALC""], [RegistrationName=""""], [CalcFileName]" If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch Set oCreate = Nothing + Set FSO = CreateScriptService("FileSystem") Check: If IsMissing(EmbeddedDatabase) Or IsEmpty(EmbeddedDatabase) Then EmbeddedDatabase = "HSQLDB" If IsMissing(RegistrationName) Or IsEmpty(RegistrationName) Then RegistrationName = "" + If IsMissing(CalcFileName) Or IsEmpty(CalcFileName) Then CalcFileName = "" If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then If Not SF_Utils._ValidateFile(FileName, "FileName") Then GoTo Finally - If Not SF_Utils._Validate(EmbeddedDatabase, "EmbeddedDatabase", V_STRING, Array("HSQLDB", "FIREBIRD")) Then GoTo Finally + If Not SF_Utils._Validate(EmbeddedDatabase, "EmbeddedDatabase", V_STRING, Array("CALC", "HSQLDB", "FIREBIRD")) Then GoTo Finally If Not SF_Utils._Validate(RegistrationName, "RegistrationName", V_STRING) Then GoTo Finally + If UCase(EmbeddedDatabase) = "CALC" Then + If Not SF_Utils._ValidateFile(CalcFileName, "CalcFileName") Then GoTo Finally + If Not FSO.FileExists(CalcFileName) Then GoTo CatchNotExists + End If End If Try: Set oDBContext = SF_Utils._GetUNOService("DatabaseContext") With oDBContext Set oDatabase = .createInstance() - oDatabase.URL = "sdbc:embedded:" & LCase(EmbeddedDatabase) + ' Build the url link to the database + Select Case UCase(EmbeddedDatabase) + Case "HSQLDB", "FIREBIRD" + oDatabase.URL = "sdbc:embedded:" & LCase(EmbeddedDatabase) + Case "CALC" + oDatabase.URL = "sdbc:calc:" & FSO._ConvertToUrl(CalcFileName) + End Select ' Create empty Base document - Set FSO = CreateScriptService("FileSystem") sFileName = FSO._ConvertToUrl(FileName) ' An existing file is overwritten without warning If FSO.FileExists(FileName) Then FSO.DeleteFile(FileName) @@ -274,6 +293,9 @@ Finally: Exit Function Catch: GoTo Finally +CatchNotExists: + SF_Exception.RaiseFatal(UNKNOWNFILEERROR, "CalcFileName", CalcFileName) + GoTo Finally End Function ' ScriptForge.SF_UI.CreateBaseDocument REM ----------------------------------------------------------------------------- @@ -1196,4 +1218,4 @@ Private Function _Repr() As String End Function ' ScriptForge.SF_UI._Repr REM ============================================ END OF SCRIPTFORGE.SF_UI -</script:module> +</script:module>
\ No newline at end of file diff --git a/wizards/source/scriptforge/python/scriptforge.py b/wizards/source/scriptforge/python/scriptforge.py index d94a7781cb97..57a67a0c9c3d 100644 --- a/wizards/source/scriptforge/python/scriptforge.py +++ b/wizards/source/scriptforge/python/scriptforge.py @@ -1472,8 +1472,9 @@ class SFScriptForge: def Activate(self, windowname = ''): return self.ExecMethod(self.vbMethod, 'Activate', windowname) - def CreateBaseDocument(self, filename, embeddeddatabase = 'HSQLDB', registrationname = ''): - return self.ExecMethod(self.vbMethod, 'CreateBaseDocument', filename, embeddeddatabase, registrationname) + def CreateBaseDocument(self, filename, embeddeddatabase = 'HSQLDB', registrationname = '', calcfilename = ''): + return self.ExecMethod(self.vbMethod, 'CreateBaseDocument', filename, embeddeddatabase, registrationname, + calcfilename) def CreateDocument(self, documenttype = '', templatefile = '', hidden = False): return self.ExecMethod(self.vbMethod, 'CreateDocument', documenttype, templatefile, hidden) |