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 do I set the properties for an XTextTable using C#?

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


Joined: 02 Jan 2009
Posts: 19

PostPosted: Tue Oct 20, 2009 8:46 am    Post subject: How do I set the properties for an XTextTable using C#? Reply with quote

Discussion on Stack Overflow

In python, I can do something like this:

Code:
table.BreakType = PAGE_BEFORE
table.HoriOrient = 0
table.RightMargin = 6.93 * 2540 - table_width


In C#, I can't find a way to set properties. XTableTable only has a few methods available to it, and none of them seem to do anything like this. How do I set properties in C#?[/url]
Back to top
View user's profile Send private message
phazzy
Power User
Power User


Joined: 26 Mar 2009
Posts: 60
Location: Bucharest, Romania

PostPosted: Wed Oct 21, 2009 6:05 am    Post subject: Reply with quote

Hello,

Now you acces your TextTable by its XTextTable interface, but the TextTable service provides many interfaces.

You have to instantiate the XPropertySet interface of the XTextTable.
Code:


// Example
XPropertySet tablePropSet = (XPropertySet)textTable;

// This is how you set a property in C#
// You have to create a new Any object to pass it as parameter
tablePropSet.setPropertyValue("HeaderRowCount", new Any(typeof(int), 1));



Look through the API :
http://api.openoffice.org/docs/common/ref/com/sun/star/beans/XPropertySet.html
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
matthewp
General User
General User


Joined: 02 Jan 2009
Posts: 19

PostPosted: Wed Oct 21, 2009 1:06 pm    Post subject: Reply with quote

Thanks phazzy,

I can't figure out how to create an Any object. Using your code (new Any(...)) doesn't work, because the compiler doesn't recognize the Any object:

Code:
The type or namespace name `Any' could not be found. Are you missing a using directive or an assembly reference?(CS0246)


This page doesn't really help, and this page makes it sound like Any is in the uno namespace, but I am already using this namespace:

Code:
using unoidl.com.sun.star.uno;


Of course, the documentation I linked to is for Java, so perhaps it is different for C#. Any ideas?
Back to top
View user's profile Send private message
phazzy
Power User
Power User


Joined: 26 Mar 2009
Posts: 60
Location: Bucharest, Romania

PostPosted: Thu Oct 22, 2009 12:42 am    Post subject: Reply with quote

The Any structure is in the uno namespace :

Code:

using System;

namespace uno
{
    public struct Any
    {
        public static Any VOID;

        public Any(bool value);
        public Any(byte value);
        public Any(char value);
        public Any(double value);
        public Any(float value);
        public Any(int value);
        public Any(long value);
        public Any(short value);
        public Any(string value);
        public Any(Type value);
        public Any(uint value);
        public Any(ulong value);
        public Any(ushort value);
        public Any(Type type, object value);

        public Type Type { get; }
        public object Value { get; }

        public bool Equals(Any obj);
        public override bool Equals(object obj);
        public override int GetHashCode();
        public bool hasValue();
        public void setValue(Type type, object value);
        public override string ToString();
    }


So, you have to include just uno : using uno;

Also, make sure you included all OO dll's as references in your project. You have to include all the dll's in the directory OFFICE_HOME\program\assembly (path valid for 2.x)

From what I see above, in uno.Any structure definition, for the basic types it has a simpler constructor, but you can use the 2-args one anyway.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
matthewp
General User
General User


Joined: 02 Jan 2009
Posts: 19

PostPosted: Thu Oct 22, 2009 6:18 pm    Post subject: Reply with quote

Thanks phazzy, using the uno namespace (instead of just unoidl.com.sun.star.uno) solved my problem.
Back to top
View user's profile Send private message
phazzy
Power User
Power User


Joined: 26 Mar 2009
Posts: 60
Location: Bucharest, Romania

PostPosted: Fri Oct 23, 2009 12:31 am    Post subject: Reply with quote

Glad I helped. You can add [SOLVED] to your thread for others to know taht have similar problems.

Cheers,

phazzy
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
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