Alaska Software Inc. - Using OpenOffice [activex]
Username: Password:
AuthorTopic: Using OpenOffice [activex]
Richard MatthewsUsing OpenOffice [activex]
on Mon, 21 Jun 2010 17:44:35 +0100
Hi everyone,

Using the OpenOffice does anyone have any examples of the document writing 
etc.

 oOffice := CreateObject( 'Com.Sun.Star.ServiceManager')
 oOffice :=oOffice:dynamicCast( ActiveXObject() )

I can't get my oWord equivalent to work with the openoffice.

-


Best regards

Richard

Richard Matthews
Smart Warehouse Systems Ltd
Simon White Re: Using OpenOffice [activex]
on Mon, 21 Jun 2010 16:27:43 -0400
Richard MatthewsRe: Using OpenOffice [activex]
on Mon, 21 Jun 2010 21:30:24 +0100
Simon,

you're a star !  Thanks

Richard
"Simon White" <SimonWhite@dciphercomputing.com> wrote in message 
news:646214d4$229bb07c$11189@news.alaska-software.com...
Hi

I use OpenOffice with Visual FoxPro for merging data with documents so I 
have included samples of my code which should be easily translated to xBase+

Simon


<pre>
PROCEDURE merge
   With This
      Do Case
      Case .cMergeType="OO"
         Local loFind
         loFind=.oMergeDoc.createReplaceDescriptor()
         For ln=1 To ALen(.aMerge,1)
             lcMerge=.aMerge(ln,2)
             lcMerge=Iif(lcMerge="=",Evaluate(Right(lcMerge,Len(lcMerge)-1)),lcMerge)
             loFind.ReplaceString=lcMerge
             loFind.SearchString=.aMerge(ln,1)
             .oMergeDoc.ReplaceAll(loFind)
         EndFor
         loFind=""
         Release loFind,ln
      Case .cMergeType="OOC"
      EndCase
   EndWith
ENDPROC
*-- The cleanup method after merging
PROCEDURE mergecleanup
   Lparameters tlVisible
   If Vartype(goApp.oPrintParam)="O"
      tlVisible=goApp.oPrintParam.PrintOptions=DC_VIEW
      goApp.oPrintParam.PrintOptions=-1
   EndIf
   With This
   Do Case

   Case .cMergeType="OO"
      If VarType(.oMergeDoc)="O"
         .oMergeDoc.getCurrentController().getFrame().getContainerWindow().setVisible(tlVisible)
      EndIf
      .oMergeDoc=""
      .oMergeSrvMgr=""
      =!tlVisible.And..oMerge.Terminate()
   EndCase
ENDPROC
*-- Opens the merge document for merging
PROCEDURE mergeopendoc
   Lparameters tcFile
   With This
      .cMergeFile=tcFile
      Do Case
      Case .cMergeType="OO".And.File(tcFile)
         Local loProp,loRefl,laArgs(2),laPrt(1)
         loRefl=.oMergeSrvMgr.createInstance("com.sun.star.reflection.CoreReflection")
         loProp=CreateObject("Empty")    && Creates an empty object that 
will become an OO property object.
         loRefl.forName("com.sun.star.beans.PropertyValue").createobject(@loProp)
         laArgs(1)=loProp
         laArgs(1).Name="ReadOnly"
         laArgs(1).Value=.N.
         laArgs(2)=loProp
         laArgs(2).Name="Hidden"
         laArgs(2).Value=.T.
         ComArray(.oMerge,10)  && convert VFP arrays to COM compatible array
         .oMergeDoc=.oMerge.loadComponentFromURL(ConvertToURL(tcFile),"_blank",0,@laArgs)
         If VarType(goApp.oPrintParam)="O"  && load printer if printer 
dialog displayed
            loProp=CreateObject("Empty")
            loRefl.forName("com.sun.star.beans.PropertyValue").createobject(@loProp)
            laPrt(1)=loProp
            laPrt(1).Name="Name"
            laPrt(1).Value=AllTrim(goApp.oPrintParam.Printer)
            ComArray(.oMergeDoc,10)
            .oMergeDoc.SetPrinter(@laPrt)
         EndIf
         Store "" to loRefl,loProp
      EndCase
   EndWith
ENDPROC
*-- Prints the merged document
PROCEDURE mergeprint
   With This
      Do Case
       Case .cMergeType="OO"
          Local loProp,loRefl,laArgs(3)
          loRefl=.oMergeSrvMgr.createInstance("com.sun.star.reflection.CoreReflection")
          loProp=CreateObject("Empty")
          loRefl.forName("com.sun.star.beans.PropertyValue").createobject(@loProp)
          laArgs(1)=loProp
          laArgs(1).Name="CopyCount"
          laArgs(1).Value=goApp.oPrintParam.Copies
          laArgs(2)=loProp
          laArgs(2).Name="Pages"
          laArgs(2).Value=Transform(goApp.oPrintParam.StartPage)+"-"+Transform(goApp.oPrintParam.LastPage)
          laArgs(3)=loProp
          laArgs(3).Name="Wait"
          laArgs(3).Value=.T.
          ComArray(.oMergeDoc,10)
          .oMergeDoc.Print(@laArgs)
          .MergeClose()
       EndCase
    EndWith
ENDPROC
*-- Sets up the merge variables.
PROCEDURE mergesetup
   LParameter tcType
   With This
      .cMergeType=tcType
      .cMergedFile=gcTmp+Sys(2015)+".rtf"
      Do Case
      Case .cMergeType="OO"
         .oMergeSrvMgr=CreateObject("com.sun.star.ServiceManager")
         .oMerge=.oMergeSrvMgr.createInstance("com.sun.star.frame.Desktop")
      EndCase
   EndWith
ENDPROC
PROCEDURE mergesave
   Lparameters tcFile
   With This
      Do Case
      Case .cMergeType="OO"
         Local loProp,loRefl,laArgs(2)
         loRefl=.oMergeSrvMgr.createInstance("com.sun.star.reflection.CoreReflection")
         loProp=CreateObject("Empty")
         loRefl.forName("com.sun.star.beans.PropertyValue").createobject(@loProp)
         laArgs(1)=loProp
         laArgs(1).Name="Overwrite"
         laArgs(1).value=.T.
         ComArray(.oMerge,10)
         .oMergeDoc.StoreAsURL(ConvertToURL(tcFile),@laArgs)
      EndCase

   EndWith
ENDPROC
*-- Close the active document
PROCEDURE mergeclose
    With This
       Do Case
       Case .cMergeType="OO"
          .oMergeDoc.setModified(.F.)
          .oMergeDoc.Close(.T.)
          .oMergeDoc=""
       EndCase
    EndWith
EndProc
</pre>




On 21/06/2010 12:44 PM, Richard Matthews wrote:
> Hi everyone,
>
> Using the OpenOffice does anyone have any examples of the document writing
> etc.
>
>   oOffice := CreateObject( 'Com.Sun.Star.ServiceManager')
>   oOffice :=oOffice:dynamicCast( ActiveXObject() )
>
> I can't get my oWord equivalent to work with the openoffice.
>
> -
>
>
> Best regards
>
> Richard
>
> Richard Matthews
> Smart Warehouse Systems Ltd
>
>
>
>


On 21/06/2010 12:44 PM, Richard Matthews wrote:
Hi everyone,

Using the OpenOffice does anyone have any examples of the document writing
etc.

 oOffice := CreateObject( 'Com.Sun.Star.ServiceManager')
 oOffice :=oOffice:dynamicCast( ActiveXObject() )

I can't get my oWord equivalent to work with the openoffice.

-


Best regards

Richard

Richard Matthews
Smart Warehouse Systems Ltd
Trinkl FerencRe: Using OpenOffice [activex]
on Wed, 23 Jun 2010 19:47:01 +0200
Hi,

Using OpenOffice activeX in Xbase++ no to easy. The trick: you must use 
VTType() undocumented function to create variant type array for OpenOffice 
argumentum:

------------------- cut ----------------------------------------
#include "ActiveX.ch"

procedure main()

  local oServiceManager, oCoreReflection
  local oDesktop, oDocument, oText, oCursor, oTable, oRow, oRows
  local oSize, oTextFrame, oFrameText, oFrameTextCursor
  local aArgs, oPropertyValue


   The service manager is always the starting point
   If there is no office running then an office is started up
  oServiceManager := CreateObject("com.sun.star.ServiceManager")

   Create the CoreReflection service that is later used to create structs
  oCoreReflection := 
oServiceManager:createInstance("com.sun.star.reflection.CoreReflection")

   Create the Desktop
  oDesktop= oServiceManager:createInstance("com.sun.star.frame.Desktop")

  oPropertyValue := 
oServiceManager:Bridge_GetStruct("com.sun.star.beans.PropertyValue")
  oPropertyValue:Name := "Hidden"
  oPropertyValue:Value := .f.
  aArgs := VTType():new({oPropertyValue}, VT_ARRAY + VT_VARIANT )

   Open a new empty writer document
  oDocument= oDesktop:loadComponentFromURL("private:factory/swriter", 
"_blank", 0, @aArgs)

   Create a text object
  oText= oDocument:getText()

   Create a cursor object
  oCursor= oText:createTextCursor()

   Inserting some Text
  oText:insertString(oCursor, "The first line in the newly created text 
document." + chr(13), .f.)

   Inserting a second line
  oText:insertString(oCursor, "Now we're in the second line.", .f.)

   Create instance of a text table with 4 columns and 4 rows
  oTable := oDocument:createInstance( "com.sun.star.text.TextTable")
  oTable:initialize(4, 4)

   Insert the table
  oText:insertTextContent(oCursor, oTable, .f.)

   Get first row
  oRows := oTable:getRows()
  oRow := oRows:getByIndex(0)

   Set the table background color
  oTable:setPropertyValue("BackTransparent", .f.)
  oTable:setPropertyValue("BackColor", 13421823)

   Set a different background color for the first row
  oRow:setPropertyValue("BackTransparent", .f.)
  oRow:setPropertyValue("BackColor", 6710932)

   Fill the first table row
  insertIntoCell("A1","FirstColumn", oTable)
  insertIntoCell("B1","SecondColumn", oTable)
  insertIntoCell("C1","ThirdColumn", oTable)
  insertIntoCell("D1","SUM", oTable)

  oTable:getCellByName("A2"):setValue(22.5)
  oTable:getCellByName("B2"):setValue(5615.3)
  oTable:getCellByName("C2"):setValue(-2315.7)
  oTable:getCellByName("D2"):setFormula("sum <A2:C2>")

  oTable:getCellByName("A3"):setValue(21.5)
  oTable:getCellByName("B3"):setValue(615.3)
  oTable:getCellByName("C3"):setValue(-315.7)
  oTable:getCellByName("D3"):setFormula("sum <A3:C3>")

  oTable:getCellByName("A4"):setValue(121.5)
  oTable:getCellByName("B4"):setValue(-615.3)
  oTable:getCellByName("C4"):setValue(415.7)
  oTable:getCellByName("D4"):setFormula("sum <A4:C4>")

   Change the CharColor and add a Shadow
  oCursor:setPropertyValue("CharColor", 255)
  oCursor:setPropertyValue("CharShadowed", .t.)

   Create a paragraph break
   The second argument is a 
com::sun::star::text::ControlCharacter::PARAGRAPH_BREAK constant
  oText:insertControlCharacter(oCursor, 0 , .f.)
   Inserting colored Text.
  oText:insertString(oCursor, " This is a colored Text - blue with shadow" + 
chr(13), .f.)

   Create a paragraph break ( ControlCharacter::PARAGRAPH_BREAK).
  oText:insertControlCharacter(oCursor, 0, .f.)

   Create a TextFrame.
  oTextFrame := oDocument:createInstance("com.sun.star.text.TextFrame")

   Create a Size struct.
  oSize := oServiceManager:Bridge_GetStruct("com.sun.star.awt.Size")
  oSize:Width := 15000
  oSize:Height := 400
  oTextFrame:setSize(@oSize)

   TextContentAnchorType.AS_CHARACTER = 1
  oTextFrame:setPropertyValue("AnchorType", 1)

   Insert the frame
  oText:insertTextContent(oCursor, oTextFrame, .f.)

   Get the text oect of the frame
  oFrameText := oTextFrame:getText()

   Create a cursor oect
  oFrameTextCursor := oFrameText:createTextCursor()

   Inserting some Text
  oFrameText:insertString(oFrameTextCursor, "The first line in the newly 
created text frame.", .f.)
  oFrameText:insertString(oFrameTextCursor, chr(13) + "With this second line 
the height of the frame raises.", .f.)

   Create a paragraph break
   The second argument is a 
com::sun::star::text::ControlCharacter::PARAGRAPH_BREAK constant
  oFrameText:insertControlCharacter(oCursor, 0 , .f.)

   Change the CharColor and add a Shadow
  oCursor:setPropertyValue("CharColor", 65536)
  oCursor:setPropertyValue("CharShadowed", .f.)

   Insert another string
  oText:insertString(oCursor, " That's all for now !!", .f.)

  return


function insertIntoCell(strCellName, strText, oTable)

  local oCellText, oCellCursor

  oCellText := oTable:getCellByName(strCellName)
  oCellCursor := oCellText:createTextCursor()
  oCellCursor:setPropertyValue("CharColor",16777215)
  oCellText:insertString(oCellCursor, strText, .f.)

  return NIL
------------------- cut ----------------------------------------

"Richard Matthews" <richard@smartwarehouse.com> az albbiakat rta a 
kvetkez hrzenetben: 69280e3a$702f0d44$f7bf@news.alaska-software.com...
> Hi everyone,
>
> Using the OpenOffice does anyone have any examples of the document writing 
> etc.
>
> oOffice := CreateObject( 'Com.Sun.Star.ServiceManager')
> oOffice :=oOffice:dynamicCast( ActiveXObject() )
>
> I can't get my oWord equivalent to work with the openoffice.
>
> -
>
>
> Best regards
>
> Richard
>
> Richard Matthews
> Smart Warehouse Systems Ltd
>
>
>
>