Hallo,
Ich benutze Visual Studio 2019, um eine Calc vorlage zu öfnnen, mit Daten zu befüllen und als pdf zu speichern.
Soweit klappt auch alles.
Ich Suche jetzt aber schon seit mehreren Tagen nach einem Beispiel um den String im Center Header zu ändern und finde dazu nichts.
Der Header Existiert schon in der Vorlage, Schriftgröße,... ist schon eingestellt. Ich will nur den Text ändern.
Hier mein Code, wie gesagt alles macht was es soll nur "AddHeader(ByVal Header As String)" ist falsch.
Code: Alles auswählen
Public Sub AddHeader(ByVal Header As String)
Try
Dim Dummy As String
Dummy = Header
' Dim oHeader As Object
'oHeader = oSheet.RightPageHeaderContent
'oSheet.RightPageHeaderContent = oHeader
Catch ex As unoidl.com.sun.star.uno.Exception
MsgBox(ex.ToString)
OpenCalcClose()
End Try
End Sub
Hier der Komplette Code:
Imports unoidl.com.sun.star.awt
Imports unoidl.com.sun.star.document
Imports unoidl.com.sun.star.lang
Imports unoidl.com.sun.star.uno
Imports unoidl.com.sun.star.bridge
Imports unoidl.com.sun.star.frame
Imports unoidl.com.sun.star.sheet
Imports unoidl.com.sun.star.beans
Imports unoidl.com.sun.star.container
Imports unoidl.com.sun.star.drawing
Imports unoidl.com.sun.star.embed
Imports unoidl.com.sun.star.table
Imports unoidl.com.sun.star.text
Imports unoidl.com.sun.star.util
Imports System
Imports System.Collections
Module OOCalc
Dim oSM As Object
' Objekte von der OpenOffice-Schnittstelle (API)
Dim oDesk, oDoc, oCell, oRows, oCols, oTables, oTable, oSheet As Object
Dim dispatcher, oBorderLine As Object
Dim NumberFormats As Object
Dim LocalSettings As Object
Dim StyleFamilies As Object
Dim oOprocess() As Process
Public Sub OpenCalcFile(ByVal Path As String)
Try
Dim arg(1) As Object
Dim Path_ As String
Path_ = "file:///" & Path
' Um Writer/Calc im Hintergrund zu halten
oOprocess = Process.GetProcessesByName("SOffice")
If oOprocess.Length > 0 Then
OpenCalcClose()
MsgBox("Eine Instance von OpenOffice ist schon offen")
End If
' OpenOffice instanziieren: Zwingend notwenig fuer die Kommunikation
' von VB.Net mit der OpenOffice API
oSM = CreateObject("com.sun.star.ServiceManager") 'Instantiate Open Office for VB
' Erstelle den ersten und wichtigsten Dienst
oDesk = oSM.createInstance("com.sun.star.frame.Desktop") 'Create service
arg(0) = oSM.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
arg(0).Name = "AsTemplate"
arg(0).Value = True
arg(1) = oSM.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
arg(1).Name = "Hidden"
arg(1).Value = False 'True
'arg = ladeZustand
'Open an existing doc, note no index on arg parameter
oDoc = oDesk.loadComponentFromURL(Path_, "_blank", 0, arg)
dispatcher = oSM.createInstance("com.sun.star.frame.DispatchHelper")
oBorderLine = oSM.createinstance("com.sun.star.style.table.BorderLine")
oTables = oSM.createInstance("com.sun.star.text.TextTables")
oTable = oSM.createInstance("com.sun.star.text.TextTable")
oSheet = oDoc.getSheets().getByIndex(0) 'Get first sheet
oTables = oDoc.getSheets()
oTable = oTables.getByName("Messwerte")
Catch ex As unoidl.com.sun.star.uno.Exception
MessageBox.Show(ex.Message)
Clipboard.SetText(ex.Message)
OpenCalcClose()
End Try
End Sub
Public Sub AddRoomCalc(ByVal saRet As String(,), ByVal StartLine As Integer)
Dim anzCols, anzRows As Integer
Dim i, j As Short
Dim value As Object
anzRows = saRet.Rank()
anzCols = (saRet.Length() / anzRows)
For i = 0 To anzRows - 1
For j = 0 To anzCols - 1
' Datenzellen
value = saRet(i, j)
oCell = oSheet.getCellByPosition(j, StartLine - 1 + i) ' Zelle für den Eintrag ermitteln
If value IsNot Nothing Then
oCell.string = value.ToString
End If
Next
Next
End Sub
Public Sub OpenCalcSave(ByVal Path As String)
Try
Dim Path_ As String
Path_ = "file:///" & Path
Dim arg(1) As Object
arg(0) = oSM.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
arg(0).Name = "FilterName"
arg(0).Value = "calc_pdf_Export"
arg(1) = oSM.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
arg(1).Name = "Overwrite"
arg(1).Value = True
'Save the doc
Call oDoc.storeToURL(Path_, arg)
'Tidy open objects
oDoc.Close(True)
oDoc = Nothing
oDesk = Nothing
oSM = Nothing
Catch ex As unoidl.com.sun.star.uno.Exception
MsgBox(ex.ToString)
OpenCalcClose()
End Try
End Sub
Public Sub OpenCalcClose()
Dim oProcess() As Process
Try
oProcess = Process.GetProcessesByName("SOffice.bin")
If oProcess.Length > 0 Then
If oDoc IsNot Nothing Then
oDoc.Close(True)
oDoc = Nothing
oDesk = Nothing
oSM = Nothing
End If
oProcess(0).Kill()
End If
Catch ex As unoidl.com.sun.star.uno.Exception
MessageBox.Show("Error " & ex.ToString)
End Try
End Sub
Public Sub AddHeader(ByVal Header As String)
Try
Dim Dummy As String
Dummy = Header
' Dim oHeader As Object
'oHeader = oSheet.RightPageHeaderContent
'oSheet.RightPageHeaderContent = oHeader
Catch ex As unoidl.com.sun.star.uno.Exception
MsgBox(ex.ToString)
OpenCalcClose()
End Try
End Sub
End Module