von DPunch » Sa, 10.07.2010 17:38
Aloha
So ohne Weiteres ist das nicht meines Wissens nach nicht möglich, aber man kann per Hand improvisieren.
Folgendes Beispiel beschriftet die Bilder automatisch mit "Abbildung" und verwendet die Kategorie "Abbildung" (also als würdest Du die Kategorie "Abbildung" für die Auto-Beschriftung für Bilder wählen).
Code: Alles auswählen
nWidth = 5000 'Breite
nHeight = 7000 'Höhe
sLabel = "Abbildung " 'Beschriftung unter dem Bild
oFilePickerDlg = createUnoService( "com.sun.star.ui.dialogs.FilePicker" )
oFilePickerDlg.appendFilter("Images","*.jpg;*.jpeg;*.gif;*.bmp;")
oFilePickerDlg.appendFilter("All files","*.*")
oFilePickerDlg.MultiSelectionMode = False
nResult = oFilePickerDlg.execute
If nResult = 0 Then Exit Sub
sImgPath = oFilePickerDlg.Files(0)
oDoc = thisComponent
oBitmaps = oDoc.createInstance( "com.sun.star.drawing.BitmapTable" )
sInternalPicName = "myPic"
For i = 0 To 200
sInternalPicName = "myPic" & i
If NOT oBitmaps.hasByName(sInternalPicName) Then Exit For
Next i
oBitmaps.insertByName(sInternalPicName, sImgPath )
If NOT oBitmaps.hasByName(sInternalPicName) Then
MsgBox("Ausgewählte Datei konnte nicht als Grafik eingefügt werden",48,"Fehler")
Exit Sub
End If
oDoc.lockControllers
oPic = oBitmaps.getByName(sInternalPicName)
oTextFrame = oDoc.createInstance("com.sun.star.text.TextFrame")
oBorder = oTextFrame.BottomBorder
With oBorder
.Color = 0
.InnerLineWidth = 0
.OuterLineWidth = 0
.LineDistance = 0
End With
With oTextFrame
.Width = nWidth
.Height = nHeight
.BottomBorder = oBorder
.TopBorder = oBorder
.RightBorder = oBorder
.LeftBorder = oBorder
.LeftMargin = 0
.RightMargin = 0
.TopMargin = 0
.BottomMargin = 0
.TextWrap = 0
.SizeType = 0
.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PARAGRAPH
End With
oCursor = oDoc.CurrentController.getViewCursor
On Local Error GoTo ErrorOccured
If NOT isEmpty(oCursor.TextTable) Then
oCursor.Cell.insertTextContent(oCursor,oTextFrame,False)
ElseIf NOT isEmpty(oCursor.TextFrame) Then
oCursor.TextFrame.insertTextContent(oCursor,oTextFrame,False)
Else
oDoc.Text.insertTextContent(oCursor,oTextFrame,False)
End If
oCursor = oTextFrame.createTextCursor
oGraph = oDoc.createInstance("com.sun.star.text.GraphicObject")
With oGraph
.GraphicURL = oPic
.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PARAGRAPH
.Width = nWidth
.Height = nHeight
End With
oTextFrame.insertTextContent(oCursor,oGraph,False)
oTextFrame.String = sLabel
oTFMaster = oDoc.TextFieldMasters.getByName("com.sun.star.text.fieldmaster.SetExpression.Illustration")
oField = oDoc.createInstance("com.sun.star.text.textfield.SetExpression")
oField.attachTextFieldMaster(oTFMaster)
oCursor.goToEnd(False)
oTextFrame.insertTextContent(oCursor,oField,False)
oCursor.goToStart(True)
oCursor.CharPosture = 2
oDoc.TextFields.refresh
Do While oDoc.hasControllersLocked
oDoc.unlockControllers
Loop
Exit Sub
ErrorOccured:
MsgBox ("Cursor an ungeeigneter Position (z.B. Grafik)",48,"Fehler")
If oBitmaps.hasByName(sInternalPicName) Then
oBitmaps.removeByName(sInternalPicName)
End If
Do While oDoc.hasControllersLocked
oDoc.unlockControllers
Loop
Aloha
So ohne Weiteres ist das nicht meines Wissens nach nicht möglich, aber man kann per Hand improvisieren.
Folgendes Beispiel beschriftet die Bilder automatisch mit "Abbildung" und verwendet die Kategorie "Abbildung" (also als würdest Du die Kategorie "Abbildung" für die Auto-Beschriftung für Bilder wählen).
[code]
nWidth = 5000 'Breite
nHeight = 7000 'Höhe
sLabel = "Abbildung " 'Beschriftung unter dem Bild
oFilePickerDlg = createUnoService( "com.sun.star.ui.dialogs.FilePicker" )
oFilePickerDlg.appendFilter("Images","*.jpg;*.jpeg;*.gif;*.bmp;")
oFilePickerDlg.appendFilter("All files","*.*")
oFilePickerDlg.MultiSelectionMode = False
nResult = oFilePickerDlg.execute
If nResult = 0 Then Exit Sub
sImgPath = oFilePickerDlg.Files(0)
oDoc = thisComponent
oBitmaps = oDoc.createInstance( "com.sun.star.drawing.BitmapTable" )
sInternalPicName = "myPic"
For i = 0 To 200
sInternalPicName = "myPic" & i
If NOT oBitmaps.hasByName(sInternalPicName) Then Exit For
Next i
oBitmaps.insertByName(sInternalPicName, sImgPath )
If NOT oBitmaps.hasByName(sInternalPicName) Then
MsgBox("Ausgewählte Datei konnte nicht als Grafik eingefügt werden",48,"Fehler")
Exit Sub
End If
oDoc.lockControllers
oPic = oBitmaps.getByName(sInternalPicName)
oTextFrame = oDoc.createInstance("com.sun.star.text.TextFrame")
oBorder = oTextFrame.BottomBorder
With oBorder
.Color = 0
.InnerLineWidth = 0
.OuterLineWidth = 0
.LineDistance = 0
End With
With oTextFrame
.Width = nWidth
.Height = nHeight
.BottomBorder = oBorder
.TopBorder = oBorder
.RightBorder = oBorder
.LeftBorder = oBorder
.LeftMargin = 0
.RightMargin = 0
.TopMargin = 0
.BottomMargin = 0
.TextWrap = 0
.SizeType = 0
.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PARAGRAPH
End With
oCursor = oDoc.CurrentController.getViewCursor
On Local Error GoTo ErrorOccured
If NOT isEmpty(oCursor.TextTable) Then
oCursor.Cell.insertTextContent(oCursor,oTextFrame,False)
ElseIf NOT isEmpty(oCursor.TextFrame) Then
oCursor.TextFrame.insertTextContent(oCursor,oTextFrame,False)
Else
oDoc.Text.insertTextContent(oCursor,oTextFrame,False)
End If
oCursor = oTextFrame.createTextCursor
oGraph = oDoc.createInstance("com.sun.star.text.GraphicObject")
With oGraph
.GraphicURL = oPic
.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PARAGRAPH
.Width = nWidth
.Height = nHeight
End With
oTextFrame.insertTextContent(oCursor,oGraph,False)
oTextFrame.String = sLabel
oTFMaster = oDoc.TextFieldMasters.getByName("com.sun.star.text.fieldmaster.SetExpression.Illustration")
oField = oDoc.createInstance("com.sun.star.text.textfield.SetExpression")
oField.attachTextFieldMaster(oTFMaster)
oCursor.goToEnd(False)
oTextFrame.insertTextContent(oCursor,oField,False)
oCursor.goToStart(True)
oCursor.CharPosture = 2
oDoc.TextFields.refresh
Do While oDoc.hasControllersLocked
oDoc.unlockControllers
Loop
Exit Sub
ErrorOccured:
MsgBox ("Cursor an ungeeigneter Position (z.B. Grafik)",48,"Fehler")
If oBitmaps.hasByName(sInternalPicName) Then
oBitmaps.removeByName(sInternalPicName)
End If
Do While oDoc.hasControllersLocked
oDoc.unlockControllers
Loop
[/code]