OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

How to declare com.sun.star.beans.PropertyValue in VB6???

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
gardb
Newbie
Newbie


Joined: 23 Oct 2003
Posts: 2

PostPosted: Thu Oct 23, 2003 9:26 am    Post subject: How to declare com.sun.star.beans.PropertyValue in VB6??? Reply with quote

Hi,
I have created some Visual Basic 6 code which manipulates a Word document "Test.doc" through OO Writer objects. Everything works just great, until I'm about to save the document. I then have to create an array of com.sun.star.beans.PropertyValue structures, but how can I do that!???

OO docs suggest this statement for OO Basic:

Dim mFileProperties(2) As New com.sun.star.beans.PropertyValue

The problem is that this type does not exists in Visual Basic 6. Have tried to do a CreateObject("com.sun.star.beans.PropertyValue") but it does not work, and that is probably logical since it is not an object, but a struct instead.

Any ideas how to solve this? Why should something so simple be so hard....? Shocked

BTW: I have to save back to Word format (.doc) and will need to set the filters-properties accordingly, anyone have examples?

-Gard
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Thu Oct 23, 2003 12:20 pm    Post subject: Reply with quote

This may seem a bit long, but you will find the solution within.

You'll notice that in all the examples I post, instead of writing....

Code:

Dim oArgs( 2 ) As com.sun.star.beans.PropertyValue
oArgs(0).Name = "foo"
oArgs(0).Value = "red"
oArgs(1).Name = "bar"
oArgs(1).Value = "green"
oArgs(2).Name = "baz"
oArgs(2).Value  = "blue"
oDoc.storeToURL( ....., oArgs() )


I instead write...

Code:

oDoc.storeToUrl( ....., Array(_
   MakePropertyValue(  "foo", "red" ),_
   MakePropertyValue( "bar", "green" ),_
   MakePropertyValue( "baz", "blue" ) ) )


That is, I create an anonymous array using a function I write to create and return a property value from its arguments. In relevant examples, I always provide the definition of MakePropertyValue.

Now what I do in VisualFoxPro is similar. I create my own function that will construct a property value from arguments, and then use a style sort of like this (bastardized VB because I don't know VB...)...

Code:

Dim oArgs( 2 ) As Variant
oArgs( 0 ) = MakePropertyValue( "foo", "red" )
oArgs( 1 ) = MakePropertyValue( "bar", "green" )
oArgs( 2 ) = MakePropertyValue( "baz", "blue" )
oDoc.storeToUrl( .....,  oArgs )


Notice that the technique is kind of a hybrid between the two extremes of the first style and my style (the second style).

You could use this technique in VB, just as I do in Visual FoxPro. What you need is a VB version of the MakePropertyValue function.

BTW, anywhere you can use a com.sun.star.beans.PropertyValue, you can probably also use a newer com.sun.star.beans.NamedValue.

Now see this post where Gibson has kindly written the equivalent of my "MakePropertyValue" function in VB. Gibson's function returns a NamedValue instead of a PropertyValue, but you should be able to use it just as well.

http://www.oooforum.org/forum/viewtopic.php?p=12231#12231

Or you could make a function to return PropertyValue's instead of NamedValue's.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
gardb
Newbie
Newbie


Joined: 23 Oct 2003
Posts: 2

PostPosted: Thu Oct 23, 2003 1:08 pm    Post subject: Reply with quote

Thanx for reply,

It was the CreateStruct function that did the trick, I eventually found it in the OO dev-docs (same as Gibson code) and then wrote the lines below, works great! Smile


Code:

Function OO_SaveDoc(ByRef oDoc As Object, ByVal sFilename As String) As Boolean
  'Save to given filename, will overwrite if exists!
  Dim aFileProperties(0) As Object  'New com.sun.star.beans.PropertyValue
  Dim sUrl As String
  sUrl = OO_GetFileURL(sFilename)
 
  Set aFileProperties(0) = OO_CreateStruct("com.sun.star.beans.PropertyValue")
  If (aFileProperties(0) Is Nothing) Then
    MsgBox "Error: Unable to get fileprops struct, aborting", vbExclamation
    Exit Function
  End If
 
  aFileProperties(0).Name = "Overwrite"
  aFileProperties(0).Value = True
  On Error Resume Next
  oDoc.storeAsURL sUrl, aFileProperties()
  If (Err.Number <> 0) Then
    MsgBox "Failed to save [" + sFilename + "], err=" + CStr(Err.Number) + ": " + Err.Description
  End If
  OO_SaveDoc = (Err.Number = 0)
End Function

Private Function OO_CreateStruct(ByVal sStructTypeName As String) As Object
  Dim oClassSize As Object
  Dim oStruct As Object
 
  On Error Resume Next
  Set oClassSize = m_oCoreReflection.forName(sStructTypeName)
  oClassSize.CreateObject oStruct
  If (Err.Number <> 0) Then
    Set oStruct = Nothing
  End If
  On Error GoTo 0

  Set OO_CreateStruct = oStruct
 
End Function

Function OO_GetFileURL(ByVal sFile As String) As String
  sFile = Replace(sFile, "\", "/") '\ not allowed, use / instead!
  sFile = Replace(sFile, ":", "|") 'X: not allowed for driveletter, use X| instead
  sFile = "file:///" + sFile       'Tripple-/ of course.... hell yea!
  OO_GetFileURL = sFile
End Function

Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Sat Oct 25, 2003 2:22 pm    Post subject: Reply with quote

See this....

http://www.oooforum.org/forum/viewtopic.php?t=3510

Use Bridge_GetStruct(), and then you don't have to mess with CoreReflection and building your own "createStruct" function.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
marc_o
General User
General User


Joined: 12 Sep 2003
Posts: 6

PostPosted: Fri Oct 31, 2003 5:13 am    Post subject: the same prob with python... Reply with quote

dear gardb, dear DannyB...

...i have the same problem, but using python!

i have seen DannyB using a self-written package name OOoLib declaring createPropertyValue. but this only works for ONE parameter.

has someone a suggestion for a set of parameters? i have tried something like this (example from StarOffice Programmers' Tutorial adopted to PYTHON):

Code:
    myArgument = ["", ""];
    myArgument[0] = createPropertyValue("Name","FilterName");
    myArgument[1] = createPropertyValue("FilterFlags","44,34,SYSTEM,1,1/1/1/1/1/1/1/1");


but it does not work.

__main__.com.sun.star.uno.RuntimeException: exceptions.AttributeError: 'list' object has np attribute 'getTypes', traceback follows\nno traceback available

so if i can not use the list-object from python... which one is the right one? ...any ideas?

hopefully, marc olejak
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Fri Oct 31, 2003 8:25 am    Post subject: Reply with quote

I have a version of my "MakePropertyValue" from Basic written in Python. In Python I call it createPropertyValue().

See this post...

http://www.oooforum.org/forum/viewtopic.php?t=3451

This post gives a bunch of my python code.

marc_o wrote:
so if i can not use the list-object from python... which one is the right one? ...any ideas?


Don't use a list of property values. Use a tupple of property values. Don't use [1, 2, 3], instead use (1, 2, 3).

See this code I wrote in the above referenced post...

Code:
# Save the newly opened document.
# Use a tupple of property values.
# The only property value is the specification of what Filter to use for saving.
oDoc.storeToURL( cTargetURL, (createPropertyValue("FilterName","writer_pdf_Export"),) )


See the tupple? See how I put parens with an extra comma around the createPropertyValue() ?

In Python, a tupple of one element is.... (1,)
In Python, a tupple of two elements is....(1,2)
In Python, a tupple of three elements is...(1,2,3)

So a tupple of one property value is...

(createPropertyValue( xxxx, yyyy ),)

A tupple of two property values is...

(createPropertyValue(x,y), createPropertyValue(z,t))

etc.

This post brought to you by the number 186282.1 plus or minus 0.04.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
marc_o
General User
General User


Joined: 12 Sep 2003
Posts: 6

PostPosted: Fri Oct 31, 2003 11:54 am    Post subject: Reply with quote

DannyB wrote:


Don't use a list of property values. Use a tupple of property values. Don't use [1, 2, 3], instead use (1, 2, 3).


thought right about that, but... correct if i am wrong...


DannyB wrote:

Code:
# Save the newly opened document.
# Use a tupple of property values.
# The only property value is the specification of what Filter to use for saving.
oDoc.storeToURL( cTargetURL, (createPropertyValue("FilterName","writer_pdf_Export"),) )


well, the LAST comma nearly killed me... it did not work, because i have not seen it.

DannyB wrote:
See the tupple? See how I put parens with an extra comma around the createPropertyValue() ?

...

A tupple of two property values is...

(createPropertyValue(x,y), createPropertyValue(z,t))


i do not know why, but it only works for me if i always end with an extra comma! example:

Code:
myDocument.storeToURL(myFileName, (createPropertyValue("FilterName","writer_pdf_Export"),createPropertyValue("Compression","2"),) );


...but THX again... and don't ask me about the "Compression"-parameter. i do not know where the others have it from... and for me it does not work. i have tried it manually with a 40MB-tif file within the exported PDF... it makes no difference... every file was about 40MB... ignoring parameters from "0-3"...

...marc olejak...
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Fri Oct 31, 2003 12:09 pm    Post subject: Reply with quote

Try CompressionMode instead of Compression.

I have no idea of where this comes from, and I cannot find it documented anywhere.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
lexu2588
General User
General User


Joined: 18 Nov 2008
Posts: 6

PostPosted: Sun Nov 30, 2008 3:42 pm    Post subject: RE Reply with quote

Dear DannyB

can u please write the code for VisualFoxPro ?

i can't make this property value for creating a table in OOo Writer because it has more than one argument and don't know how to do this
can u help me? please
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
lexu2588
General User
General User


Joined: 18 Nov 2008
Posts: 6

PostPosted: Sun Nov 30, 2008 3:48 pm    Post subject: RE2 Reply with quote

i tried like this:

Code:

LOCAL ARRAY NoArg[1]
LOCAL loOfcMgr, loDesktop, loDocument, args(1), loCoreReflection,;
     loPropertyValue,loText,loCursor, loSourceFrame, loDisp, oct1
* Create the Service Manger and Desktop
loOfcMgr = CreateObject("com.sun.star.ServiceManager")
loDesktop = loOfcMgr.createInstance("com.sun.star.frame.Desktop")

** The args array is an array of "PropertyValue - objects - create by invoking OO.o reflection
loCoreReflection = loOfcMgr.createInstance("com.sun.star.reflection.CoreReflection" )
loPropertyValue = CREATEOBJECT("Empty")
loCoreReflection.forName("com.sun.star.beans.PropertyValue"). createobject(@loPropertyValue)
args[1] = loPropertyValue
args[1].name = "ReadOnly"
args[1].value = .F.

* Tell VFP to pass arrays to the loDesktop object as zero-based, by reference
COMARRAY(loDesktop,10)
* Open a new empty writer document
loDocument = loDesktop.loadComponentFromURL("private:factory/swriter","_blank", 0, @args)

** Create dispatcher
octl = loDocument.getCurrentController()
loSourceframe = octl.getFrame()
loDisp = loOfcMgr.CreateInstance( "com.sun.star.frame.DispatchHelper" )

** Insert sample Text
loText=loDocument.getText() && Create text object
* Create a cursor object (position pointer)
loCursor= loText.createTextCursor()


** Align text
NoArg[1] = loPropertyValue
NoArg[1].name = "JustifyPara"
NoArg[1].value = .T.
loDisp.executeDispatch(octl, ".uno:JustifyPara", "", 0, @ NoArg)

** Insert text
loCursor.CharHeight = 12
loCursor.CharWeight = 100
loText.insertString(loCursor, "JUSTIFIED TEXT ALIGNED TO BOTH LEFT & RIGHT"+CHR(13),.F.)

*************** this is the part that's not working :
LOCAL aArgs1[1]
aArgs1[1] = loPropertyValue
aArgs1[1].name = "TableName"
aArgs1[1].value = "Table1"
aArgs1[1].name = "Colums"
aArgs1[1].value = 1
aArgs1[1].name = "Rows"
aArgs1[1].value = 1
aArgs1[1].name = "Flags"
aArgs1[1].value = 9
loDisp.executeDispatch(octl, ".uno:InsertTable", "", 0, @ aArgs1)



how can i insert the table ??
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
ublio88
Newbie
Newbie


Joined: 01 Mar 2009
Posts: 1

PostPosted: Sun Mar 01, 2009 2:37 pm    Post subject: create table Reply with quote

INSTEAD OF YOUR NOT-WORKING CODE TRY THIS:
------------------------------------------------------------------------------------------------
LOCAL ARRAY NoArg[1]
LOCAL loOfcMgr, loDesktop, loDocument, args(1), loCoreReflection,;
loPropertyValue,loText,loCursor, loSourceFrame, loDisp, oct1
* Create the Service Manger and Desktop
loOfcMgr = CreateObject("com.sun.star.ServiceManager")
loDesktop = loOfcMgr.createInstance("com.sun.star.frame.Desktop")

** The args array is an array of "PropertyValue - objects - create by invoking OO.o reflection
loCoreReflection = loOfcMgr.createInstance("com.sun.star.reflection.CoreReflection" )
loPropertyValue = CREATEOBJECT("Empty")
loCoreReflection.forName("com.sun.star.beans.PropertyValue"). createobject(@loPropertyValue)
args[1] = loPropertyValue
args[1].name = "ReadOnly"
args[1].value = .F.
* Tell VFP to pass arrays to the loDesktop object as zero-based, by reference
COMARRAY(loDesktop,10)
* Open a new empty writer document
loDocument = loDesktop.loadComponentFromURL("private:factory/swriter","_blank", 0, @args)
** Create dispatcher
octl = loDocument.getCurrentController()
loSourceframe = octl.getFrame()
loDisp = loOfcMgr.CreateInstance( "com.sun.star.frame.DispatchHelper" )
** Insert sample Text
loText=loDocument.getText() && Create text object
* Create a cursor object (position pointer)
loCursor= loText.createTextCursor()
**
loCursor.CharHeight = 16
loCursor.CharWeight = 100
loText.insertString(loCursor, 'Good day!',.F.)

LOCAL ARRAY NoArg[1],NoArg[2],NoArg[3],NoArg[4]
NoArg[1] = loPropertyValue
NoArg[1].Name = "TableName"
NoArg[1].Value = "Table1"
NoArg[2] = loPropertyValue
NoArg[2].Name = "Columns"
NoArg[2].Value = 2
NoArg[3] = loPropertyValue
NoArg[3].Name = "Rows"
NoArg[3].Value = 2
NoArg[4] = loPropertyValue
NoArg[4].Name = "Flags"
NoArg[4].Value = 9
loDisp.executeDispatch(octl, ".uno:InsertTable", "", 0, @ NoArg)


OR THIS:
------------------------------------------------------------------------------------------------
LOCAL ARRAY NoArg[1]
LOCAL loOfcMgr, loDesktop, loDocument, args(1), loCoreReflection,;
loPropertyValue,loText,loCursor, loSourceFrame, loDisp, oct1
* Create the Service Manger and Desktop
loOfcMgr = CreateObject("com.sun.star.ServiceManager")
loDesktop = loOfcMgr.createInstance("com.sun.star.frame.Desktop")

** The args array is an array of "PropertyValue - objects - create by invoking OO.o reflection
loCoreReflection = loOfcMgr.createInstance("com.sun.star.reflection.CoreReflection" )
loPropertyValue = CREATEOBJECT("Empty")
loCoreReflection.forName("com.sun.star.beans.PropertyValue"). createobject(@loPropertyValue)
args[1] = loPropertyValue
args[1].name = "ReadOnly"
args[1].value = .F.
* Tell VFP to pass arrays to the loDesktop object as zero-based, by reference
COMARRAY(loDesktop,10)
* Open a new empty writer document
loDocument = loDesktop.loadComponentFromURL("private:factory/swriter","_blank", 0, @args)
** Create dispatcher
octl = loDocument.getCurrentController()
loSourceframe = octl.getFrame()
loDisp = loOfcMgr.CreateInstance( "com.sun.star.frame.DispatchHelper" )
** Insert sample Text
loText=loDocument.getText() && Create text object
* Create a cursor object (position pointer)
loCursor= loText.createTextCursor()
**
loCursor.CharHeight = 16
loCursor.CharWeight = 100
loText.insertString(loCursor, 'Good day!',.F.)

** Prepare and insert Table
LOCAL loTable, loViewCursor, loCell, loText, loCursor
loTable = loDocument.createInstance ("com.sun.star.text.TextTable")
loTable.initialize( 1, 1 )
loViewCursor = loDocument.getCurrentController().getViewCursor()
loText = loDocument.getText()
loText.insertTextContent( loViewCursor, loTable, .F. )
loCell = loTable.getCellByPosition( 0, 0 )
loText = loCell.getText()
loCursor = loText.createTextCursor()

** text in table
loCursor.CharHeight = 10
loCursor.CharWeight = 100
loText.insertString(loCursor, "Good day!", .F.)
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group