mirror of
https://gitee.com/kekingcn/file-online-preview.git
synced 2026-03-19 15:43:47 +08:00
移除office-plugin, 使用新版jodconverter
This commit is contained in:
464
server/windows-office/share/basic/SFDocuments/SF_Base.xba
Normal file
464
server/windows-office/share/basic/SFDocuments/SF_Base.xba
Normal file
@@ -0,0 +1,464 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
|
||||
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="SF_Base" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
|
||||
REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
|
||||
REM === The SFDocuments library is one of the associated libraries. ===
|
||||
REM === Full documentation is available on https://help.libreoffice.org/ ===
|
||||
REM =======================================================================================================================
|
||||
|
||||
Option Compatible
|
||||
Option ClassModule
|
||||
|
||||
Option Explicit
|
||||
|
||||
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
''' SF_Base
|
||||
''' =======
|
||||
'''
|
||||
''' The SFDocuments library gathers a number of methods and properties making easy
|
||||
''' the management and several manipulations of LibreOffice documents
|
||||
'''
|
||||
''' Some methods are generic for all types of documents: they are combined in the SF_Document module.
|
||||
''' Specific properties and methods are implemented in the concerned subclass(es) SF_Calc, SF_Writer, ...
|
||||
'''
|
||||
''' To workaround the absence of class inheritance in LibreOffice Basic, some redundancy is necessary
|
||||
''' Each subclass MUST implement also the generic methods and properties, even if they only call
|
||||
''' the parent methods and properties.
|
||||
''' They should also duplicate some generic private members as a subset of their own set of members
|
||||
'''
|
||||
''' The SF_Base module is provided only to block parent properties that are NOT applicable to Base documents
|
||||
'''
|
||||
''' The current module is closely related to the "UI" service of the ScriptForge library
|
||||
'''
|
||||
''' Service invocation examples:
|
||||
''' 1) From the UI service
|
||||
''' Dim ui As Object, oDoc As Object
|
||||
''' Set ui = CreateScriptService("UI")
|
||||
''' Set oDoc = ui.CreateBaseDocument("C:\Me\MyFile.odb", ...)
|
||||
''' ' or Set oDoc = ui.OpenDocument("C:\Me\MyFile.odb")
|
||||
''' 2) Directly if the document is already opened
|
||||
''' Dim oDoc As Object
|
||||
''' Set oDoc = CreateScriptService("SFDocuments.Base", "MyFile.odb")
|
||||
''' ' The substring "SFDocuments." in the service name is optional
|
||||
'''
|
||||
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
|
||||
REM ================================================================== EXCEPTIONS
|
||||
|
||||
Private Const DBCONNECTERROR = "DBCONNECTERROR"
|
||||
|
||||
REM ============================================================= PRIVATE MEMBERS
|
||||
|
||||
Private [Me] As Object
|
||||
Private [_Parent] As Object
|
||||
Private [_Super] As Object ' Document superclass, which the current instance is a subclass of
|
||||
Private ObjectType As String ' Must be BASE
|
||||
Private ServiceName As String
|
||||
|
||||
' Window component
|
||||
Private _Component As Object ' com.sun.star.comp.dba.ODatabaseDocument
|
||||
Private _DataSource As Object ' com.sun.star.comp.dba.ODatabaseSource
|
||||
Private _Database As Object ' SFDatabases.Database service instance
|
||||
|
||||
REM ============================================================ MODULE CONSTANTS
|
||||
|
||||
REM ===================================================== CONSTRUCTOR/DESTRUCTOR
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Sub Class_Initialize()
|
||||
Set [Me] = Nothing
|
||||
Set [_Parent] = Nothing
|
||||
Set [_Super] = Nothing
|
||||
ObjectType = "BASE"
|
||||
ServiceName = "SFDocuments.Base"
|
||||
Set _Component = Nothing
|
||||
Set _DataSource = Nothing
|
||||
Set _Database = Nothing
|
||||
End Sub ' SFDocuments.SF_Base Constructor
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Sub Class_Terminate()
|
||||
Call Class_Initialize()
|
||||
End Sub ' SFDocuments.SF_Base Destructor
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Dispose() As Variant
|
||||
If Not IsNull([_Super]) Then Set [_Super] = [_Super].Dispose()
|
||||
Call Class_Terminate()
|
||||
Set Dispose = Nothing
|
||||
End Function ' SFDocuments.SF_Base Explicit Destructor
|
||||
|
||||
REM ================================================================== PROPERTIES
|
||||
|
||||
REM ===================================================================== METHODS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function CloseDocument(Optional ByVal SaveAsk As Variant) As Boolean
|
||||
''' The closure of a Base document requires the closures of
|
||||
''' 1) the connection => done in the CloseDatabase() method
|
||||
''' 2) the data source
|
||||
''' 3) the document itself => done in the superclass
|
||||
|
||||
Const cstThisSub = "SFDocuments.Base.CloseDocument"
|
||||
Const cstSubArgs = "[SaveAsk=True]"
|
||||
|
||||
If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
|
||||
Check:
|
||||
If IsMissing(SaveAsk) Or IsEmpty(SaveAsk) Then SaveAsk = True
|
||||
If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not [_Super]._IsStillAlive(True) Then GoTo Finally
|
||||
If Not ScriptForge.SF_Utils._Validate(SaveAsk, "SaveAsk", V_BOOLEAN) Then GoTo Finally
|
||||
End If
|
||||
|
||||
Try:
|
||||
If Not IsNull(_Database) Then _Database.CloseDatabase()
|
||||
If Not IsNull(_DataSource) Then _DataSource.dispose()
|
||||
CloseDocument = [_Super].CloseDocument(SaveAsk)
|
||||
|
||||
Finally:
|
||||
ScriptForge.SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' SFDocuments.SF_Base.CloseDocument
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function GetDatabase(Optional ByVal User As Variant _
|
||||
, Optional ByVal Password As Variant _
|
||||
) As Object
|
||||
''' Returns a Database instance (service = SFDatabases.Database) giving access
|
||||
''' to the execution of SQL commands on the database defined and/or stored in
|
||||
''' the actual Base document
|
||||
''' Args:
|
||||
''' User, Password: the login parameters as strings. Defaults = ""
|
||||
''' Returns:
|
||||
''' A SFDatabases.Database instance or Nothing
|
||||
''' Example:
|
||||
''' Dim myDb As Object
|
||||
''' Set myDb = oDoc.GetDatabase()
|
||||
|
||||
Const cstThisSub = "SFDocuments.Base.GetDatabase"
|
||||
Const cstSubArgs = "[User=""""], [Password=""""]"
|
||||
|
||||
If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
Set GetDatabase = Nothing
|
||||
|
||||
Check:
|
||||
If IsMissing(User) Or IsEmpty(User) Then User = ""
|
||||
If IsMissing(Password) Or IsEmpty(Password) Then Password = ""
|
||||
If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not [_Super]._IsStillAlive(True) Then GoTo Finally
|
||||
If Not ScriptForge.SF_Utils._Validate(User, "User", V_STRING) Then GoTo Finally
|
||||
If Not ScriptForge.SF_Utils._Validate(Password, "Password", V_STRING) Then GoTo Finally
|
||||
End If
|
||||
|
||||
Try:
|
||||
If IsNull(_Database) Then ' 1st connection from the current document instance
|
||||
If IsNull(_DataSource) Then GoTo CatchConnect
|
||||
Set _Database = ScriptForge.SF_Services.CreateScriptService("SFDatabases.DatabaseFromDocument" _
|
||||
, _DataSource, User, Password)
|
||||
If IsNull(_Database) Then GoTo CatchConnect
|
||||
_Database._Location = [_Super]._WindowFileName
|
||||
EndIf
|
||||
|
||||
Finally:
|
||||
Set GetDatabase = _Database
|
||||
ScriptForge.SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
CatchConnect:
|
||||
ScriptForge.SF_Exception.RaiseFatal(DBCONNECTERROR, "User", User, "Password", Password, [_Super]._FileIdent())
|
||||
GoTo Finally
|
||||
End Function ' SFDocuments.SF_Base.GetDatabase
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant
|
||||
''' Return the actual value of the given property
|
||||
''' Args:
|
||||
''' PropertyName: the name of the property as a string
|
||||
''' Returns:
|
||||
''' The actual value of the property
|
||||
''' Exceptions:
|
||||
''' ARGUMENTERROR The property does not exist
|
||||
|
||||
Const cstThisSub = "SFDocuments.Base.GetProperty"
|
||||
Const cstSubArgs = ""
|
||||
|
||||
If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
GetProperty = Null
|
||||
|
||||
Check:
|
||||
If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not ScriptForge.SF_Utils._Validate(PropertyName, "PropertyName", V_STRING, Properties()) Then GoTo Catch
|
||||
End If
|
||||
|
||||
Try:
|
||||
' Superclass or subclass property ?
|
||||
If ScriptForge.SF_Array.Contains([_Super].Properties(), PropertyName) Then
|
||||
GetProperty = [_Super].GetProperty(PropertyName)
|
||||
Else
|
||||
GetProperty = _PropertyGet(PropertyName)
|
||||
End If
|
||||
|
||||
Finally:
|
||||
ScriptForge.SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' SFDocuments.SF_Base.GetProperty
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Methods() As Variant
|
||||
''' Return the list of public methods of the Model service as an array
|
||||
|
||||
Methods = Array( _
|
||||
"Activate" _
|
||||
, "CloseDocument" _
|
||||
, "GetDatabase" _
|
||||
, "RunCommand" _
|
||||
, "Save" _
|
||||
, "SaveAs" _
|
||||
, "SaveCopyAs" _
|
||||
)
|
||||
|
||||
End Function ' SFDocuments.SF_Base.Methods
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Properties() As Variant
|
||||
''' Return the list or properties of the Timer class as an array
|
||||
|
||||
Properties = Array( _
|
||||
"DocumentType" _
|
||||
, "IsBase" _
|
||||
, "IsCalc" _
|
||||
, "IsDraw " _
|
||||
, "IsImpress" _
|
||||
, "IsMath" _
|
||||
, "IsWriter" _
|
||||
, "XComponent" _
|
||||
)
|
||||
|
||||
End Function ' SFDocuments.SF_Base.Properties
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function SetProperty(Optional ByVal PropertyName As Variant _
|
||||
, Optional ByRef Value As Variant _
|
||||
) As Boolean
|
||||
''' Set a new value to the given property
|
||||
''' Args:
|
||||
''' PropertyName: the name of the property as a string
|
||||
''' Value: its new value
|
||||
''' Exceptions
|
||||
''' ARGUMENTERROR The property does not exist
|
||||
|
||||
Const cstThisSub = "SFDocuments.Base.SetProperty"
|
||||
Const cstSubArgs = "PropertyName, Value"
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
SetProperty = False
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(PropertyName, "PropertyName", V_STRING, Properties()) Then GoTo Catch
|
||||
End If
|
||||
|
||||
Try:
|
||||
Select Case UCase(PropertyName)
|
||||
Case Else
|
||||
End Select
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' SFDocuments.SF_Documents.SetProperty
|
||||
|
||||
REM ======================================================= SUPERCLASS PROPERTIES
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
'Property Get CustomProperties() As Variant
|
||||
' CustomProperties = [_Super].GetProperty("CustomProperties")
|
||||
'End Property ' SFDocuments.SF_Base.CustomProperties
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
'Property Let CustomProperties(Optional ByVal pvCustomProperties As Variant)
|
||||
' [_Super].CustomProperties = pvCustomProperties
|
||||
'End Property ' SFDocuments.SF_Base.CustomProperties
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
'Property Get Description() As Variant
|
||||
' Description = [_Super].GetProperty("Description")
|
||||
'End Property ' SFDocuments.SF_Base.Description
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
'Property Let Description(Optional ByVal pvDescription As Variant)
|
||||
' [_Super].Description = pvDescription
|
||||
'End Property ' SFDocuments.SF_Base.Description
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
'Property Get DocumentProperties() As Variant
|
||||
' DocumentProperties = [_Super].GetProperty("DocumentProperties")
|
||||
'End Property ' SFDocuments.SF_Base.DocumentProperties
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get DocumentType() As String
|
||||
DocumentType = [_Super].GetProperty("DocumentType")
|
||||
End Property ' SFDocuments.SF_Base.DocumentType
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get IsBase() As Boolean
|
||||
IsBase = [_Super].GetProperty("IsBase")
|
||||
End Property ' SFDocuments.SF_Base.IsBase
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get IsCalc() As Boolean
|
||||
IsCalc = [_Super].GetProperty("IsCalc")
|
||||
End Property ' SFDocuments.SF_Base.IsCalc
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get IsDraw() As Boolean
|
||||
IsDraw = [_Super].GetProperty("IsDraw")
|
||||
End Property ' SFDocuments.SF_Base.IsDraw
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get IsImpress() As Boolean
|
||||
IsImpress = [_Super].GetProperty("IsImpress")
|
||||
End Property ' SFDocuments.SF_Base.IsImpress
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get IsMath() As Boolean
|
||||
IsMath = [_Super].GetProperty("IsMath")
|
||||
End Property ' SFDocuments.SF_Base.IsMath
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get IsWriter() As Boolean
|
||||
IsWriter = [_Super].GetProperty("IsWriter")
|
||||
End Property ' SFDocuments.SF_Base.IsWriter
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
'Property Get Keywords() As Variant
|
||||
' Keywords = [_Super].GetProperty("Keywords")
|
||||
'End Property ' SFDocuments.SF_Base.Keywords
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
'Property Let Keywords(Optional ByVal pvKeywords As Variant)
|
||||
' [_Super].Keywords = pvKeywords
|
||||
'End Property ' SFDocuments.SF_Base.Keywords
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
'Property Get Readonly() As Variant
|
||||
' Readonly = [_Super].GetProperty("Readonly")
|
||||
'End Property ' SFDocuments.SF_Base.Readonly
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
'Property Get Subject() As Variant
|
||||
' Subject = [_Super].GetProperty("Subject")
|
||||
'End Property ' SFDocuments.SF_Base.Subject
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
'Property Let Subject(Optional ByVal pvSubject As Variant)
|
||||
' [_Super].Subject = pvSubject
|
||||
'End Property ' SFDocuments.SF_Base.Subject
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
'Property Get Title() As Variant
|
||||
' Title = [_Super].GetProperty("Title")
|
||||
'End Property ' SFDocuments.SF_Base.Title
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
'Property Let Title(Optional ByVal pvTitle As Variant)
|
||||
' [_Super].Title = pvTitle
|
||||
'End Property ' SFDocuments.SF_Base.Title
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get XComponent() As Variant
|
||||
XComponent = [_Super].GetProperty("XComponent")
|
||||
End Property ' SFDocuments.SF_Base.XComponent
|
||||
|
||||
REM ========================================================== SUPERCLASS METHODS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Activate() As Boolean
|
||||
Activate = [_Super].Activate()
|
||||
End Function ' SFDocuments.SF_Base.Activate
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Sub RunCommand(Optional ByVal Command As Variant)
|
||||
[_Super].RunCommand(Command)
|
||||
End Sub ' SFDocuments.SF_Base.RunCommand
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Save() As Boolean
|
||||
Save = [_Super].Save()
|
||||
End Function ' SFDocuments.SF_Base.Save
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function SaveAs(Optional ByVal FileName As Variant _
|
||||
, Optional ByVal Overwrite As Variant _
|
||||
, Optional ByVal Password As Variant _
|
||||
, Optional ByVal FilterName As Variant _
|
||||
, Optional ByVal FilterOptions As Variant _
|
||||
) As Boolean
|
||||
SaveAs = [_Super].SaveAs(FileName, Overwrite, Password, FilterName, FilterOptions)
|
||||
End Function ' SFDocuments.SF_Base.SaveAs
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function SaveCopyAs(Optional ByVal FileName As Variant _
|
||||
, Optional ByVal Overwrite As Variant _
|
||||
, Optional ByVal Password As Variant _
|
||||
, Optional ByVal FilterName As Variant _
|
||||
, Optional ByVal FilterOptions As Variant _
|
||||
) As Boolean
|
||||
SaveCopyAs = [_Super].SaveCopyAs(FileName, Overwrite, Password, FilterName, FilterOptions)
|
||||
End Function ' SFDocuments.SF_Base.SaveCopyAs
|
||||
|
||||
REM =========================================================== PRIVATE FUNCTIONS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _PropertyGet(Optional ByVal psProperty As String _
|
||||
, Optional ByVal pvArg As Variant _
|
||||
) As Variant
|
||||
''' Return the value of the named property
|
||||
''' Args:
|
||||
''' psProperty: the name of the property
|
||||
|
||||
Dim oProperties As Object ' Document or Custom properties
|
||||
Dim vLastCell As Variant ' Coordinates of last used cell in a sheet
|
||||
Dim oSelect As Object ' Current selection
|
||||
Dim vRanges As Variant ' List of selected ranges
|
||||
Dim i As Long
|
||||
Dim cstThisSub As String
|
||||
Const cstSubArgs = ""
|
||||
|
||||
_PropertyGet = False
|
||||
|
||||
cstThisSub = "SFDocuments.SF_Base.get" & psProperty
|
||||
ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
|
||||
If Not [_Super]._IsStillAlive() Then GoTo Finally
|
||||
|
||||
Select Case psProperty
|
||||
Case Else
|
||||
_PropertyGet = Null
|
||||
End Select
|
||||
|
||||
Finally:
|
||||
ScriptForge.SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
End Function ' SFDocuments.SF_Base._PropertyGet
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _Repr() As String
|
||||
''' Convert the SF_Base instance to a readable string, typically for debugging purposes (DebugPrint ...)
|
||||
''' Args:
|
||||
''' Return:
|
||||
''' "[Base]: Type/File"
|
||||
|
||||
_Repr = "[Base]: " & [_Super]._FileIdent()
|
||||
|
||||
End Function ' SFDocuments.SF_Base._Repr
|
||||
|
||||
REM ============================================ END OF SFDOCUMENTS.SF_BASE
|
||||
</script:module>
|
||||
Reference in New Issue
Block a user