INTEGRACAO COM O OPENOFFICE

MARCIOR 03/08/2010 11:20:04
#349267
necessito criar uma integração com o openoffice, documento de texto (writer), mais ou menos como a do word abaixo. como faço a referência?

Set objWord = New Word.Application
objWord.Visible = True
Set objDoc = objWord.Documents.Open(App.Path & [Ô]\SOCIAL.doc[Ô])
objDoc.Activate
objDoc.Bookmarks([Ô]Local1[Ô]).Range.Text = [Ô]Concórdia/SC, [Ô] & Format$(Date, [Ô]dd \d\e mmmm \d\e yyyy[Ô]) & [Ô].[Ô]
[ô]objDoc.Bookmarks([Ô]Local2[Ô]).Range.Text = [Ô]Concórdia/SC, [Ô] & Format$(Date, [Ô]dd \d\e mmmm \d\e yyyy[Ô]) & [Ô].[Ô]
objDoc.Bookmarks([Ô]Nome[Ô]).Range.Text = Form1.TxtNome.Text
objDoc.Bookmarks([Ô]CPF[Ô]).Range.Text = Form1.TxtCPFCNPJ.Text


[ô]objDoc.Paragraph.Alignment = wdAlignParagraphJustify

[ô]Para justificar um texto


Set objDoc = Nothing
Set objWord = Nothing

[ô]Imprime direto
[ô]ActiveDocument.PrintOut

[ô]Exibe a caixa de impressão
[ô]Dialogs(wdDialogFilePrint).Show
List1.AddItem Command1.Caption
MARCIOR 10/08/2010 15:13:48
#349905
pessoal achei este código na net que quase resolveu minha necessidade, mas estou com problemas para achar o código equivalente de : (objDoc.Bookmarks([Ô]Nome[Ô]).Range.Text = Form1.TxtNome.Text ) do word para o writer...
tentei com a instrução : oDoc.Bookmarks([Ô]Teste2[Ô]).getByName([Ô]New_Bookmark_End[Ô]).getAnchor.setString ([Ô]**Inserted at [ô][Ô] & strBkName & [Ô][ô] by VBA code** [Ô])
mas sem sucesso.
O que realmente necessito agora é fazer uma refernecia a Indice Criado no writer para preencher o documento nas posições que escolher via indice.


[ô]Private Sub Command2_Click()
Sub bk_demo()
[ô]
[ô] Bookmark demo
[ô]
[ô] You need an existing writer doc (c:    mp    estdoc.odt),
[ô] execute in step by step mode to follow
[ô] result in the doc (use Writer navigator to see bookmarks)
[ô]
[ô] Note : this sample code works with writer documents (sxw or odt formats)
[ô] as well as with MsOffice Word documents
[ô]

Dim oSM, oDesk, oDoc, oTxt, oBk, oRng As Object [ô]OOo objects
Dim strBkName As String
Dim arg()

Set oSM = CreateObject([Ô]com.sun.star.ServiceManager[Ô])
Set oDesk = oSM.createInstance([Ô]com.sun.star.frame.Desktop[Ô])
Set oDoc = oDesk.loadComponentFromURL([Ô]file:///C:/tmp/testdoc.odt[Ô], [Ô]_blank[Ô], 0, arg())

[ô]Set oDoc = oDesktop.loadComponentFromURL([Ô]file:///[Ô] & Replace(App.Path, [Ô]\[Ô], [Ô]/[Ô]) & [Ô]/testDoc.odt[Ô], [Ô]_blank[Ô], 0, aNoArgs()) [ô]abre o documento

Set oTxt = oDoc.Text

[ô]Inserts a bookmark at the beginning of the text
Set oBk = oDoc.createInstance([Ô]com.sun.star.text.Bookmark[Ô])
oBk.Name = [Ô]New_Bookmark_Beginning[Ô]
Set oRng = oTxt.getStart()
Call oTxt.insertTextContent(oRng, oBk, True)

[ô]Inserts a bookmark at the end of the text
Set oBk = oDoc.createInstance([Ô]com.sun.star.text.Bookmark[Ô])
oBk.Name = [Ô]New_Bookmark_End[Ô]
Set oRng = oTxt.getEnd()
Call oTxt.insertTextContent(oRng, oBk, True)

[ô]Inserts some text at an existing bookmark, requested by name
strBkName = [Ô]New_Bookmark_End[Ô]

[ô]objDoc.Bookmarks([Ô]Nome[Ô]).Range.Text = Form1.TxtNome.Text
oDoc.Bookmarks([Ô]Teste2[Ô]).getByName([Ô]New_Bookmark_End[Ô]).getAnchor.setString ([Ô]**Inserted at [ô][Ô] & strBkName & [Ô][ô] by VBA code** [Ô])



[ô]Deletes an existing bookmark, requested by name
[ô]strBkName = [Ô]New_Bookmark_End[Ô]
[ô]Set oBk = oDoc.getBookmarks().getByName(strBkName)
[ô]Set oTxt = oDoc.Text
[ô]Call oTxt.removeTextContent(oBk)

[ô]Cleaning all objects
[ô]Call oDoc.Close(False) [ô]Close without saving
Set oBk = Nothing
Set oRng = Nothing
Set oTxt = Nothing
Set oDoc = Nothing
Set oDesk = Nothing
Set oSM = Nothing

End Sub
MARCIOR 10/08/2010 15:21:56
#349907
o correto é Indicador em vez de indice...
MARCIOR 10/08/2010 17:29:14
#349916
Colegas, para quem precisar...

no documento writer do openoficce : inserir Marcador


Private Sub Command1_Click()
Dim aNoArgs()
Set oServiceManager = CreateObject([Ô]com.sun.star.ServiceManager[Ô]) [ô]cria o objet service manager
Set oDesktop = oServiceManager.createInstance([Ô]com.sun.star.frame.Desktop[Ô]) [ô]cria o objeto desktop
[ô]Set oDoc = oDesktop.loadComponentFromURL([Ô]file:///[Ô] & Replace(App.Path, [Ô]\[Ô], [Ô]/[Ô]) & [Ô]/teste.ods[Ô], [Ô]_blank[Ô], 0, aNoArgs()) [ô]abre o documento

Set oDoc = oDesktop.loadComponentFromURL([Ô]file:///[Ô] & Replace(App.Path, [Ô]\[Ô], [Ô]/[Ô]) & [Ô]/teste.odt[Ô], [Ô]_blank[Ô], 0, aNoArgs()) [ô]abre o documento

Set oSheet = oDoc.getSheets().getByIndex(0) [ô]seleciona primeira planilha

Call oSheet.getCellByPosition(3, 1).SetValue(111) [ô]seta valor col,linha

[ô]Call oSheet.getCellByPosition(3, 1).SetValue(111) [ô]seta valor col,linha
[ô]Call oSheet.getCellByPosition(3, 2).SetValue(222) [ô]seta valor col,linha
[ô]Call oSheet.getCellByPosition(3, 3).SetString([Ô]Nilson[Ô]) [ô]seta valor da celular do tipo string
[ô]Call oSheet.getCellByPosition(3, 5).SetFormula([Ô]=SUM(D2:D4)[Ô]) [ô]seta celula do tipo formula

End [ô]sai do programa
End Sub

Function MakePropertyValue(cName, uValue) As Object
Set oServiceManager = CreateObject([Ô]com.sun.star.ServiceManager[Ô])
Dim oStruct
Set oStruct = oServiceManager.Bridge_GetStruct([Ô]com.sun.star.beans.PropertyValue[Ô])
oStruct.Name = cName
oStruct.Value = uValue
Set MakePropertyValue = oStruct
End Function

[ô]Private Sub Command2_Click()
Sub bk_demo()
[ô]
[ô] Bookmark demo
[ô]
[ô] You need an existing writer doc (c:    mp    estdoc.odt),
[ô] execute in step by step mode to follow
[ô] result in the doc (use Writer navigator to see bookmarks)
[ô]
[ô] Note : this sample code works with writer documents (sxw or odt formats)
[ô] as well as with MsOffice Word documents
[ô]

Dim oSM, oDesk, oDoc, oTxt, oBk, oRng As Object [ô]OOo objects
Dim strBkName As String
Dim arg()

Set oSM = CreateObject([Ô]com.sun.star.ServiceManager[Ô])
Set oDesk = oSM.createInstance([Ô]com.sun.star.frame.Desktop[Ô])
Set oDoc = oDesk.loadComponentFromURL([Ô]file:///C:/tmp/testdoc.odt[Ô], [Ô]_blank[Ô], 0, arg())


[ô]Set oDoc = oDesktop.loadComponentFromURL([Ô]file:///[Ô] & Replace(App.Path, [Ô]\[Ô], [Ô]/[Ô]) & [Ô]/testDoc.odt[Ô], [Ô]_blank[Ô], 0, aNoArgs()) [ô]abre o documento

Set oTxt = oDoc.Text

[ô]Inserts a bookmark at the beginning of the text
Set oBk = oDoc.createInstance([Ô]com.sun.star.text.Bookmark[Ô])
oBk.Name = [Ô]New_Bookmark_Beginning[Ô]
Set oRng = oTxt.getStart()
Call oTxt.insertTextContent(oRng, oBk, True)

[ô]Inserts a bookmark at the end of the text
Set oBk = oDoc.createInstance([Ô]com.sun.star.text.Bookmark[Ô])
[ô]oBk.Name = [Ô]teste4[Ô]
Set oRng = oTxt.getEnd()
Call oTxt.insertTextContent(oRng, oBk, True)

[ô]Inserts some text at an existing bookmark, requested by name

[ô]Dim args1(0) As New com.sun.star.beans.PropertyValue
[ô]args1(0).Name = [Ô]Bookmark[Ô]
[ô]args1(0).Value = [Ô]teste4[Ô]

[ô]dispatcher.executeDispatch(document, [Ô].uno:InsertBookmark[Ô], [Ô][Ô], 0, args1())


[ô]strBkName = [Ô]teste4[Ô]

[ô]objDoc.Bookmarks([Ô]Nome[Ô]).Range.Text = Form1.TxtNome.Text

oDoc.Bookmarks().getByName([Ô]TESTE10[Ô]).getAnchor.setString ([Ô]TEXTO1[Ô])

oDoc.Bookmarks().getByName([Ô]TESTE11[Ô]).getAnchor.setString ([Ô]TEXTO2[Ô])

oDoc.Bookmarks().getByName([Ô]TESTE12[Ô]).getAnchor.setString ([Ô]TEXTO3[Ô])

oDoc.Bookmarks().getByName([Ô]TESTE13[Ô]).getAnchor.setString ([Ô]TEXTO4[Ô])
[ô]oDoc.getBookmarks().getByName([Ô]teste4[Ô]).Value ([Ô]121[Ô])


[ô]Deletes an existing bookmark, requested by name
[ô]strBkName = [Ô]New_Bookmark_End[Ô]
[ô]Set oBk = oDoc.getBookmarks().getByName(strBkName)
[ô]Set oTxt = oDoc.Text
[ô]Call oTxt.removeTextContent(oBk)

[ô]Cleaning all objects
[ô]Call oDoc.Close(False) [ô]Close without saving
Set oBk = Nothing
Set oRng = Nothing
Set oTxt = Nothing
Set oDoc = Nothing
Set oDesk = Nothing
Set oSM = Nothing

End Sub

[ô]End Sub
Private Sub Command2_Click()
bk_demo
End Sub
Tópico encerrado , respostas não são mais permitidas