You are viewing a plain text version of this content. The canonical link for it is here.
Posted to api@openoffice.apache.org by "K.Misha" <mi...@4k.com.ua> on 2013/09/19 13:36:24 UTC

Change column property in XTextTable

Hello!

 

I have this code:

 

Reference < XTextDocument > xTextDocument (xWriterComponent,UNO_QUERY);

Reference< XModel > aDrawDoc (xTextDocument, UNO_QUERY);

Reference<XMultiServiceFactory> aFact(aDrawDoc,UNO_QUERY);

Reference< XTextTable > xTextTable(
aFact->createInstance(OUString::createFromAscii("com.sun.star.text.TextTable
")), UNO_QUERY);

 

xTextTable->initialize(4,4);

 

Reference<XText> xText = xTextDocument->getText();

Reference<XTextRange> xTextRange = xText->getStart();

Reference<XTextContent> xTextContent(xTextTable, UNO_QUERY);

 

xText->insertTextContent( xTextRange, xTextContent, 0 );

 

Reference<XTableColumns> xTableColumns = xTextTable->getColumns();

Any rCol = xTableColumns->getByIndex(0);

 

Reference< XPropertySet > xPropSet2(rCol, UNO_QUERY);

Any mPropVal1 <<= makeAny((unsigned short)150);

 

But here i have an error:

xPropSet2->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("Width")),
mPropVal1);

 

Can you help me with changing column properties in text table?

 

Thanks!


RE: Change column property in XTextTable

Posted by "K.Misha" <mi...@4k.com.ua>.
Thanks!<неи<неи-----Original Message-----<неиFrom: Peter Eberlein
[mailto:pet.ebe@refofd.verwalt-berlin.de] <неиSent: Thursday, September 19,
2013 5:24 PM<неиTo: api@openoffice.apache.org<неиSubject: Re: Change column
property in XTextTable<неи<неиHi,<неиAm 19.09.2013 13:36, schrieb
K.Misha:<неи> Hello!<неи><неи><неи><неи> I have this
code:<неи><неи><неи><неи> Reference < XTextDocument > xTextDocument
(xWriterComponent,UNO_QUERY);<неи><неи> Reference< XModel > aDrawDoc
(xTextDocument, UNO_QUERY);<неи><неи> Reference<XMultiServiceFactory>
aFact(aDrawDoc,UNO_QUERY);<неи><неи> Reference< XTextTable >
xTextTable(<неи>
aFact->createInstance(OUString::createFromAscii("com.sun.star.text.TextTable
<неи> ")), UNO_QUERY);<неи><неи><неи><неи>
xTextTable->initialize(4,4);<неи><неи><неи><неи> Reference<XText> xText =
xTextDocument->getText();<неи><неи> Reference<XTextRange> xTextRange =
xText->getStart();<неи><неи> Reference<XTextContent>
xTextContent(xTextTable, UNO_QUERY);<неи><неи><неи><неи>
xText->insertTextContent( xTextRange, xTextContent, 0 );<неи><неи><неи><неи>
Reference<XTableColumns> xTableColumns = xTextTable->getColumns();<неи><неи>
Any rCol = xTableColumns->getByIndex(0);<неи><неи><неи><неи> Reference<
XPropertySet > xPropSet2(rCol, UNO_QUERY);<неи><неи> Any mPropVal1 <<=
makeAny((unsigned short)150);<неи><неи><неи><неи> But here i have an
error:<неи><неи>
xPropSet2->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("Width")),<
неи> mPropVal1);<неи><неи><неи><неи> Can you help me with changing column
properties in text table?<неи><неи<неиyou have to use the
com.sun.star.text.TableColumnSeparator.<неи<неиIn Java this can look like
this:<неи<неиXTextTablesSupplier xTablesSupplier = (XTextTablesSupplier)
<неиUnoRuntime.queryInterface(XTextTablesSupplier.class,
xTextDocument);<неиXTextTable xTextTable = (XTextTable)
<неиUnoRuntime.queryInterface(XTextTable.class,
<неиxTablesSupplier.getTextTables().getByName("Table1"));<неиXPropertySet
xPropertySet = (XPropertySet)
<неиUnoRuntime.queryInterface(XPropertySet.class,
xTextTable);<неиcom.sun.star.text.TableColumnSeparator[] sep =
(TableColumnSeparator[])
<неиxPropertySet.getPropertyValue("TableColumnSeparators");<неиsep[0].Positi
on = 1000;<неиxPropertySet.setPropertyValue("TableColumnSeparators",
sep);<неи<неиRegards<неи<неиPeter<неи<неи-----------------------------------
----------------------------------<неиTo unsubscribe, e-mail:
api-unsubscribe@openoffice.apache.org<неиFor additional commands, e-mail:
api-help@openoffice.apache.org<неи<неи


---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
For additional commands, e-mail: api-help@openoffice.apache.org


Re: Change column property in XTextTable

Posted by Peter Eberlein <pe...@refofd.verwalt-berlin.de>.
Hi,
Am 19.09.2013 13:36, schrieb K.Misha:
> Hello!
>
>
>
> I have this code:
>
>
>
> Reference < XTextDocument > xTextDocument (xWriterComponent,UNO_QUERY);
>
> Reference< XModel > aDrawDoc (xTextDocument, UNO_QUERY);
>
> Reference<XMultiServiceFactory> aFact(aDrawDoc,UNO_QUERY);
>
> Reference< XTextTable > xTextTable(
> aFact->createInstance(OUString::createFromAscii("com.sun.star.text.TextTable
> ")), UNO_QUERY);
>
>
>
> xTextTable->initialize(4,4);
>
>
>
> Reference<XText> xText = xTextDocument->getText();
>
> Reference<XTextRange> xTextRange = xText->getStart();
>
> Reference<XTextContent> xTextContent(xTextTable, UNO_QUERY);
>
>
>
> xText->insertTextContent( xTextRange, xTextContent, 0 );
>
>
>
> Reference<XTableColumns> xTableColumns = xTextTable->getColumns();
>
> Any rCol = xTableColumns->getByIndex(0);
>
>
>
> Reference< XPropertySet > xPropSet2(rCol, UNO_QUERY);
>
> Any mPropVal1 <<= makeAny((unsigned short)150);
>
>
>
> But here i have an error:
>
> xPropSet2->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("Width")),
> mPropVal1);
>
>
>
> Can you help me with changing column properties in text table?
>

you have to use the com.sun.star.text.TableColumnSeparator.

In Java this can look like this:

XTextTablesSupplier xTablesSupplier = (XTextTablesSupplier) 
UnoRuntime.queryInterface(XTextTablesSupplier.class, xTextDocument);
XTextTable xTextTable = (XTextTable) 
UnoRuntime.queryInterface(XTextTable.class, 
xTablesSupplier.getTextTables().getByName("Table1"));
XPropertySet xPropertySet = (XPropertySet) 
UnoRuntime.queryInterface(XPropertySet.class, xTextTable);
com.sun.star.text.TableColumnSeparator[] sep = (TableColumnSeparator[]) 
xPropertySet.getPropertyValue("TableColumnSeparators");
sep[0].Position = 1000;
xPropertySet.setPropertyValue("TableColumnSeparators", sep);

Regards

Peter

---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
For additional commands, e-mail: api-help@openoffice.apache.org


Re: Change column property in XTextTable

Posted by Ariel Constenla-Haile <ar...@apache.org>.
Hi,

On Thu, Sep 19, 2013 at 02:36:24PM +0300, K.Misha wrote:
> Can you help me with changing column properties in text table?

The columns width is handled by the property TableColumnSeparators of
the table, see
http://wiki.openoffice.org/wiki/Documentation/DevGuide/Text/Text_Table_Properties

An example, assuming that you have a 6 columns table, each column will
have by default the same with, 16.6 %; we want the first column to be
only the 10%, and the other columns have the same width; the following
code snippet does this:


Reference< XPropertySet > rTablePropertySet ( rTextTable, UNO_QUERY_THROW );

sal_Int16 nReltativeSum( 0 );
rTablePropertySet->getPropertyValue(
    OUString( RTL_CONSTASCII_USTRINGPARAM(
                    "TableColumnRelativeSum" ) ) ) >>= nReltativeSum;

// by default, every column has the same width
// with 6 columns, every column is 16.6 % of the column relative sum
// make the first column a 10 %
sal_Int16 nFirstColumn( nReltativeSum / 10 );
sal_Int16 nOtherCols( ( nReltativeSum - nFirstColumn ) / 5 );
sal_Int16 nPosition( nFirstColumn );

// in general, you get the sequence from the table's TableColumnSeparators
// but as we've just created the table and know the column count,
// there is no need to do so
Sequence< TableColumnSeparator > aColSeparators( 5 );
aColSeparators[0].Position = nPosition;
aColSeparators[0].IsVisible = sal_True;
aColSeparators[1].Position = nPosition += nOtherCols;
aColSeparators[1].IsVisible = sal_True;
aColSeparators[2].Position = nPosition += nOtherCols;
aColSeparators[2].IsVisible = sal_True;
aColSeparators[3].Position = nPosition += nOtherCols;
aColSeparators[3].IsVisible = sal_True;
aColSeparators[4].Position = nPosition += nOtherCols;
aColSeparators[4].IsVisible = sal_True;

rTablePropertySet->setPropertyValue(
    OUString( RTL_CONSTASCII_USTRINGPARAM( "TableColumnSeparators" ) ),
    makeAny( aColSeparators ) );


The full example is attached.


Regards
-- 
Ariel Constenla-Haile
La Plata, Argentina