Makros/Basis/Dokumente
< Macros
TDF LibreOffice Document Liberation Project Community Blogs Weblate Nextcloud Redmine Ask LibreOffice Spende
⇐ Zurück zum Inhaltsverzeichnis
Aktives Dokument
Sub Main()
doc = ThisComponent
MsgBox doc.Title
End Sub
alle offenen Dokumente
For Each doc In StarDesktop.Components
MsgBox doc.Title
Next
neue Dokumente
- Calc
Dim path As String
Dim args()
path = "private:factory/scalc"
doc = StarDesktop.loadComponentFromURL(path, "_default", 0, args())
- Für Writer:
"private:factory/swriter"
- Für Impress:
"private:factory/simpress"
- Für Draw:
"private:factory/sdraw"
- Für Math:
"private:factory/smath"
- Für Base
Dim path As String, dbc As Object, db As Object
Dim args()
path = ConvertToURL("/home/USER/My_db.odb")
dbc = createUnoService("com.sun.star.sdb.DatabaseContext")
db = dbc.createInstance()
db.URL = "sdbc:embedded:firebird"
db.DatabaseDocument.storeAsURL(path, args())
Dokumente öffnen
Dim path As String
Dim doc As Object
Dim args()
path = ConvertToUrl("/home/USER/My_file_Calc.ods")
doc = StarDesktop.loadComponentFromURL(path, "default", 0, args())
Einsatz von Argumenten zum Öffnen
- Öffnen wie eine Vorlage
Dim path As String
Dim doc As Object
Dim args(0) As New "com.sun.star.beans.PropertyValue"
args(0).Name = "AsTemplate"
args(0).Value = True
path = ConvertToUrl("/home/USER/My_file_Calc.ods")
doc = StarDesktop.loadComponentFromURL(path, "default", 0, args())
- oder normal öffnen, wenn die Datei eine Vorlage ist
args(0).Name = "AsTemplate"
args(0).Value = False
path = ConvertToUrl("/home/USER/My_template_Calc.odt")
doc = StarDesktop.loadComponentFromURL(path, "default", 0, args())
- andere übliche Agumente, zum nur lesen öffnen.
args(0).Name = "ReadOnly"
args(0).Value = True
- mit Passwort
args(0).Name = "Password"
args(0).Value = "letmein"
- mit aktiven Makros
args(0).Name = "MacroExecutionMode"
args(0).Value = 4
- Präsentation automatisch starten
args(0).Name = "StartPresentation"
args(0).Value = True
- Vorschau Ansicht
args(0).Name = "Preview"
args(0).Value = True
- versteckt öffnen
args(0).Name = "Hidden"
args(0).Value = True
über Dialog öffnen
Dim dlg_select_file as Object
Dim files() As String
Dim args()
Dim path As String
Dim doc As Object
dlg_select_file = CreateUnoService("com.sun.star.ui.dialogs.FilePicker")
dlg_select_file.setTitle("Select one file")
If dlg_select_file.Execute() Then
path = dlg_select_file.getFiles()(0)
doc = StarDesktop.loadComponentFromURL(path, "_default", 0, args())
End If
Dokument speichern
- Für offene Dokumente
path = ConvertToUrl("/home/USER/My_file_Calc.ods")
doc = StarDesktop.loadComponentFromURL(path, "default", 0, args())
MsgBox doc.Title
doc.store()
doc.close(True)
- Für neue Dokumente
Dim args()
path = "private:factory/scalc"
doc = StarDesktop.loadComponentFromURL(path, "_default", 0, args())
path = ConvertToUrl("/home/mau/new_doc_calc.ods")
doc.storeAsURL(path, args())
- Verwendung anderer Optionen, Speichern mit Passwort
Dim args(0) As New "com.sun.star.beans.PropertyValue"
path = "private:factory/scalc"
doc = StarDesktop.loadComponentFromURL(path, "_default", 0, args())
args(0).Name = "Password"
args(0).Value = "letmein"
path = ConvertToUrl("/home/mau/new_doc_calc.ods")
doc.storeAsURL(path, args())
- Verwendung von Filtern für Formatänderungen
Dim args(0) As New "com.sun.star.beans.PropertyValue"
path = "private:factory/swriter"
doc = StarDesktop.loadComponentFromURL(path, "_default", 0, args())
args(0).Name = "FilterName"
args(0).Value = "MS Word 97"
path = ConvertToUrl("/home/mau/new_doc_Word.doc")
doc.storeAsURL(path, args())
über Dialog speichern
Only show the selected path for user, you need add code for save in line 15.
Dim dlg_save as Object
Dim mArchivo() As String
Dim mOpciones()
dlg_save = CreateUnoService("com.sun.star.ui.dialogs.FilePicker")
'com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_AUTOEXTENSION_PASSWORD = 2
With dlg_save
.Initialize(Array(2))
.AppendFilter("Text documents ODF (.odt)", "*.odt" )
.AppendFilter("Spreadsheet ODF (.ods)", "*.ods" )
End With
If dlg_save.Execute() Then
path = dlg_save.getFiles()(0)
MsgBox ConvertFromUrl(path)
End If
Nach PDF exportieren
- für Calc Dokumente
Dim args(0) As New "com.sun.star.beans.PropertyValue"
Dim path As String
Dim doc As Object
doc = ThisComponent
args(0).Name = "FilterName"
args(0).Value = "calc_pdf_Export"
path = ConvertToURL("/home/USER/output.pdf")
doc.storeToURL(path, args())
- für Writer Dokumente
args(0).Name = "FilterName"
args(0).Value = "writer_pdf_Export"
- For Draw document
args(0).Name = "FilterName"
args(0).Value = "draw_pdf_Export"
- For Impress document
args(0).Name = "FilterName"
args(0).Value = "impress_pdf_Export"
Set focus
documents = StarDesktop.getComponents()
enumeration = documents.createEnumeration()
Do While enumeration.hasMoreElements()
doc = enumeration.nextElement()
window = doc.CurrentController.Frame.ComponentWindow
window.setFocus()
REM 1,5 Sekunden Pause
Wait 1500
Loop
Status bar
doc = ThisComponent
status_bar = doc.CurrentController.StatusIndicator
REM Default Text und Grenzwerte setzen
status_bar.start("In line ", 10)
For i = 1 To 10
status_bar.setValue(i)
status_bar.setText("Line: " & i)
Wait 1000
Next
REM Wichtig für Statuszeile
status_bar.end()
Zoom
doc = ThisComponent
cc = doc.CurrentController
cc.ZoomValue = 150