PowerBuilder and OpenOffice.org

The Application Programming Interface and the OASIS Open Document Format

PowerBuilder and OpenOffice.org

Postby Xlapatsas » Fri Mar 02, 2012 3:02 pm

Hello to everybody,

I'm trying to add OpenOffice capabilities in my PowerBuilder applications, however I couldn't manage to do anything using the OpenOffice API documentation.My goal is to select and copy text from one part of a document to another and also add a table at the end of the document.In the API's documentation I read that I need to declare UNO objects.In order to get the code I need, I edited the document and I recorded my macro.Then I tried to implement this macro code to PowerBuilder code. This is the code I used:

Code: Select all   Expand viewCollapse view
OLEObject  iuo_OLE,l_dispatcher,l_table,l_objPropertyValues[],i_objDesktop,l_objDocument,l_emptyArray[]
Long ll_Error
ll_Error = iuo_OLE.ConnectToNewObject("com.sun.star.ServiceManager")
if ll_Error = 0 Then //This is 0 meaning that the connection is succesfull      
   i_objDesktop = iuo_OLE.createInstance("com.sun.star.frame.Desktop")
        l_objPropertyValues[1] = i_objCoreReflection.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
        l_objPropertyValues[1].Name = "ReadOnly"
        l_objPropertyValues[1].Value  = "false"
        l_objDocument = i_objDesktop.loadComponentFromURL(ls_fileURL, "_blank", 0, l_objPropertyValues) //so far I get no error messages
     
        l_dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
        l_dispatcher.executeDispatch(document, ".uno:Copy", "", 0, l_emptyArray)
        l_dispatcher.executeDispatch(document, ".uno:InsertTable", "", 0, l_emptyArray)
give me the error message "error calling external method createUnoService"

OR
When I tried the code from API Documentation to create the table

Code: Select all   Expand viewCollapse view
l_emptycursor =  l_emptyDocument.Text.createTextCursor()
l_table = l_objDocument.createInstance("com.sun.star.text.TextTable")
l_table.initialize(5,4)
l_objDocument.Text.insertTextContent(l_emptycursor, l_table, False)
End If


but I still get an "error calling external method insertTextContent".
Can anybody help me on what I am doing wrong?I appreciate any help.

Harry
OpenOffice 3.3 on Windows 7
Xlapatsas
 
Posts: 3
Joined: Fri Mar 02, 2012 1:12 pm

Re: PowerBuilder and OpenOffice

Postby FJCC » Fri Mar 02, 2012 3:28 pm

I wouldn't use the dispatcher methods produced by a recorded macro. That method are very limited. I think your last bit of code will work if you pass a TextRange as the first parameter of insertTextContent. You can use the Start or End property of the cursor, for example
Code: Select all   Expand viewCollapse view
    l_emptycursor =  l_emptyDocument.Text.createTextCursor()
    l_table = l_objDocument.createInstance("com.sun.star.text.TextTable")
    l_table.initialize(5,4)
    l_objDocument.Text.insertTextContent(l_emptycursor.End, l_table, False)
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 8104
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: PowerBuilder and OpenOffice

Postby B Marcelly » Fri Mar 02, 2012 3:38 pm

Hi,
CreateUnoService is a OOoBasic helper. For your language it should be replaced by iuo_OLE.createInstance
Code: Select all   Expand viewCollapse view
l_dispatcher = iuo_OLE.createInstance("com.sun.star.frame.DispatchHelper")


When I tried the code from API Documentation to create the table

The cursor must be created on the text object where you insert the table. Seeing the names of your variables, it is not on the same document.
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
B Marcelly
Volunteer
 
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: PowerBuilder and OpenOffice.org

Postby Xlapatsas » Mon Mar 05, 2012 11:56 am

Thank you both for your answers.The problem in my code as B Marcelly suggested, was that I used different names for my documents.I corrected this and now it works fine!I finally managed to create my table!To move forward I changed my initialize line to:
Code: Select all   Expand viewCollapse view
l_table.initialize(1,2)

and I created a table with one row and two columns.I need to set the first column's width to 70% of the total table width and the second column to 30% of the total table width.I read in the API's Documentation that I must use the TableColumnSeparators attribute of my table.So I have added the following code :
Code: Select all   Expand viewCollapse view
OLEObject l_objRows,l_objRow l_tableCols[]
l_objRows = l_table.GetRows()
l_objRow = l_objRows.getByIndex(0)
l_tableCols = l_objRow.TableColumnSeparators()
l_tableCols[1].Position = 7000
l_tableCols[2].Position = 3000
l_objRow.TableColumnSeparators = l_tableCols

but I get the error : "error accessing external object property Position ".

Any ideas?Is there any other way to modify my table columns?
OpenOffice 3.3 on Windows 7
Xlapatsas
 
Posts: 3
Joined: Fri Mar 02, 2012 1:12 pm

Re: PowerBuilder and OpenOffice.org

Postby B Marcelly » Mon Mar 05, 2012 12:49 pm

Xlapatsas wrote:Any ideas?Is there any other way to modify my table columns?

You are on OOo 3.3.
Same problem as here.
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
B Marcelly
Volunteer
 
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: PowerBuilder and OpenOffice.org

Postby Xlapatsas » Tue Mar 06, 2012 11:00 am

Thanks for your reply Bernard. I have installed OpenOffice 3.2.1 as you advised and I tried again the following code:
Code: Select all   Expand viewCollapse view
OLEObject l_objRows,l_objRow l_tableCols[]
l_objRows = l_table.GetRows()
l_objRow = l_objRows.getByIndex(0)
l_tableCols = l_objRow.TableColumnSeparators()
l_tableCols[1].Position = 7000
l_tableCols[2].Position = 3000
l_objRow.TableColumnSeparators = l_tableCols


which gives me the " error:type mismatch in array-to-object conversion" for the line 'l_tableCols = l_table.TableColumnSeparators'.
Version 3.3 of OpenOffice gave me the "error accessing external object property Position".

Are there any mistakes in my code?
OpenOffice 3.3 on Windows 7
Xlapatsas
 
Posts: 3
Joined: Fri Mar 02, 2012 1:12 pm

Re: PowerBuilder and OpenOffice.org

Postby Cold_Burn » Tue May 29, 2012 7:53 pm

Xlapatsas wrote:Thanks for your reply Bernard. I have installed OpenOffice 3.2.1 as you advised and I tried again the following code:
Code: Select all   Expand viewCollapse view
OLEObject l_objRows,l_objRow l_tableCols[]
l_objRows = l_table.GetRows()
l_objRow = l_objRows.getByIndex(0)
l_tableCols = l_objRow.TableColumnSeparators()
l_tableCols[1].Position = 7000
l_tableCols[2].Position = 3000
l_objRow.TableColumnSeparators = l_tableCols


which gives me the " error:type mismatch in array-to-object conversion" for the line 'l_tableCols = l_table.TableColumnSeparators'.
Version 3.3 of OpenOffice gave me the "error accessing external object property Position".

Are there any mistakes in my code?


Registered just to answer you. :mrgreen:
There are no mistakes in your code. Call it a "Powerbuilder thing". I was having the same error you describe.

Try this way:

Code: Select all   Expand viewCollapse view
any ioo_objTblColSeps[]
OLEObject ioo_objTblColSepsOLE[]

long ll_p

ioo_objTable = ioo_objDesktop.getcurrentcomponent().getTextTables().getByIndex(0)
ioo_objTblColSeps = ioo_objTable.TableColumnSeparators //the any array here does the trick

//recover the any elements and put them on a OLEObject Array
for ll_p = 1 to  upperbound(ioo_objTblColSeps)
   ioo_objTblColSepsOLE[ll_p] = ioo_objTblColSeps[ll_p]
next

//Rem Change the positions of the two separators.
ioo_objTblColSepsOLE[1].Position = 7000 //this would give an error if the any array was used here
ioo_objTblColSepsOLE[2].Position = 9000
//REM You must assign the array back
ioo_objTable.TableColumnSeparators = ioo_objTblColSeps


This example it's just for two columns but I'm sure you can change it to suit your interests.
By the way, I'm using 3.1.0 with Windows XP PRO SP3 (signature).

Tell me if it worked for you.
Cold_Burn
OpenOffice 3.1.0 on Windows XP PRO SP3 32bits
User avatar
Cold_Burn
 
Posts: 10
Joined: Tue May 29, 2012 7:38 pm

Re: PowerBuilder and OpenOffice.org

Postby marcos » Wed Dec 12, 2012 5:03 am

Please give us a running script... plssss... thank you.
OpenOffice.org 3.3 W7
marcos
 
Posts: 1
Joined: Tue Dec 11, 2012 11:40 am


Return to UNO API and ODF

Who is online

Users browsing this forum: No registered users and 1 guest