Hi, On Thu, Sep 19, 2013 at 11:32:50PM +0300, K.Misha wrote: > Code in attached file makes TextTable like this: > > > > > > But how i can make table like this:
The answer is in the code snippet in the API documentation: http://www.openoffice.org/api/docs/common/ref/com/sun/star/text/TextTable.html Set the HoriOrient property to NONE and then set the LeftMargin and RightMargin; or try other combinations, like in the attached example. Regards -- Ariel Constenla-Haile La Plata, Argentina
#include <iostream> #include <cppuhelper/bootstrap.hxx> #include <rtl/ustring.hxx> /** === begin UNO includes === **/ #include <com/sun/star/beans/PropertyValue.hpp> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/chart/XChartData.hpp> #include <com/sun/star/chart/XChartDataArray.hpp> #include <com/sun/star/chart/XChartDocument.hpp> #include <com/sun/star/document/XEmbeddedObjectSupplier.hpp> #include <com/sun/star/frame/XComponentLoader.hpp> #include <com/sun/star/lang/XComponent.hpp> #include <com/sun/star/lang/XMultiComponentFactory.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/sheet/XCellRangeData.hpp> #include <com/sun/star/sheet/XCellRangeData.hpp> #include <com/sun/star/table/XCell.hpp> #include <com/sun/star/table/XTableRows.hpp> #include <com/sun/star/text/ControlCharacter.hpp> #include <com/sun/star/text/TableColumnSeparator.hpp> #include <com/sun/star/text/HoriOrientation.hpp> #include <com/sun/star/text/XText.hpp> #include <com/sun/star/text/XTextContent.hpp> #include <com/sun/star/text/XTextCursor.hpp> #include <com/sun/star/text/XTextDocument.hpp> #include <com/sun/star/text/XTextTable.hpp> #include <com/sun/star/text/XTextTableCursor.hpp> #include <com/sun/star/uno/XComponentContext.hpp> /** === end UNO includes === **/ /** === begin UNO using === **/ using ::com::sun::star::beans::PropertyValue; using ::com::sun::star::beans::XPropertySet; using ::com::sun::star::chart::XChartData; using ::com::sun::star::chart::XChartDataArray; using ::com::sun::star::chart::XChartDocument; using ::com::sun::star::document::XEmbeddedObjectSupplier; using ::com::sun::star::frame::XComponentLoader; using ::com::sun::star::lang::XComponent; using ::com::sun::star::lang::XMultiComponentFactory; using ::com::sun::star::lang::XMultiServiceFactory; using ::com::sun::star::sheet::XCellRangeData; using ::com::sun::star::sheet::XCellRangeData; using ::com::sun::star::table::XCell; using ::com::sun::star::table::XTableRows; using ::com::sun::star::text::TableColumnSeparator; using ::com::sun::star::text::XText; using ::com::sun::star::text::XTextContent; using ::com::sun::star::text::XTextCursor; using ::com::sun::star::text::XTextDocument; using ::com::sun::star::text::XTextTable; using ::com::sun::star::text::XTextTableCursor; using ::com::sun::star::uno::Any; using ::com::sun::star::uno::Exception; using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::RuntimeException; using ::com::sun::star::uno::Sequence; using ::com::sun::star::uno::UNO_QUERY_THROW; using ::com::sun::star::uno::UNO_QUERY_THROW; using ::com::sun::star::uno::XComponentContext; using ::com::sun::star::uno::XInterface; using ::com::sun::star::uno::makeAny; /** === end UNO using === **/ using namespace std; using rtl::OUString; namespace ControlCharacter = ::com::sun::star::text::ControlCharacter; int SAL_CALL main( int argc, char *argv[] ) { try { // bootstrap the office Reference< XComponentContext > rContext ( ::cppu::bootstrap() ); Reference< XMultiComponentFactory > rMCF( rContext->getServiceManager() ); // instantiate the Desktop and get a reference to XComponentLoader Reference < XComponentLoader > rComponentLoader( rMCF->createInstanceWithContext( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ) ), rContext ), UNO_QUERY_THROW ); // load a new empty OOo Writer document Reference< XTextDocument > rTextDocument ( rComponentLoader->loadComponentFromURL( OUString( RTL_CONSTASCII_USTRINGPARAM( "private:factory/swriter" ) ), OUString( RTL_CONSTASCII_USTRINGPARAM( "_blank" ) ), 0, Sequence < ::com::sun::star::beans::PropertyValue >() ), UNO_QUERY_THROW ); // get the XText interface Reference< XText > rText = rTextDocument->getText(); // create a text cursor Reference< XTextCursor > rTextCursor = rText->createTextCursor(); rTextCursor->gotoStart( sal_False ); rText->insertString( rTextCursor.get(), OUString( RTL_CONSTASCII_USTRINGPARAM( "Default table:" ) ), sal_False ); // insert a paragraph break rText->insertControlCharacter( rTextCursor.get(), ControlCharacter::PARAGRAPH_BREAK, sal_False ); // get the document's factory Reference< XMultiServiceFactory > rDocFactory( rTextDocument, UNO_QUERY_THROW ); // create a text table Reference< XTextTable > rTextTable ( rDocFactory->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextTable" ) ) ), UNO_QUERY_THROW ); // initalize it with 5 rows and 6 columns rTextTable->initialize( sal_Int32( 5 ), sal_Int32( 6 ) ); // insert it in the document rText->insertTextContent( rTextCursor.get(), rTextTable.get() , sal_False ); //---------------------------------------------------------------------- rText->insertString( rTextCursor.get(), OUString( RTL_CONSTASCII_USTRINGPARAM( "Table: center alignment, 80 % relative width" ) ), sal_False ); // insert a paragraph break rText->insertControlCharacter( rTextCursor.get(), ControlCharacter::PARAGRAPH_BREAK, sal_False ); rTextTable.set( rDocFactory->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextTable" ) ) ), UNO_QUERY_THROW ); // initalize it with 5 rows and 6 columns rTextTable->initialize( sal_Int32( 5 ), sal_Int32( 6 ) ); // insert it in the document rText->insertTextContent( rTextCursor.get(), rTextTable.get() , sal_False ); Reference< XPropertySet > rTablePropertySet ( rTextTable, UNO_QUERY_THROW ); rTablePropertySet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "HoriOrient" ) ), makeAny( com::sun::star::text::HoriOrientation::CENTER ) ); rTablePropertySet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "RelativeWidth" ) ), makeAny( sal_Int16( 80 ) ) ); //---------------------------------------------------------------------- rText->insertString( rTextCursor.get(), OUString( RTL_CONSTASCII_USTRINGPARAM( "Table: manual alignment, left and right margins" ) ), sal_False ); // insert a paragraph break rText->insertControlCharacter( rTextCursor.get(), ControlCharacter::PARAGRAPH_BREAK, sal_False ); rTextTable.set( rDocFactory->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextTable" ) ) ), UNO_QUERY_THROW ); // initalize it with 5 rows and 6 columns rTextTable->initialize( sal_Int32( 5 ), sal_Int32( 6 ) ); // insert it in the document rText->insertTextContent( rTextCursor.get(), rTextTable.get() , sal_False ); rTablePropertySet.set( rTextTable, UNO_QUERY_THROW ); rTablePropertySet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "HoriOrient" ) ), makeAny( com::sun::star::text::HoriOrientation::NONE ) ); rTablePropertySet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "LeftMargin" ) ), makeAny( sal_Int32( 3000 ) ) ); rTablePropertySet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "RightMargin" ) ), makeAny( sal_Int32( 1500 ) ) ); cout << "Press ENTER to finish the example"; cin.get(); } catch ( Exception &e ) { cerr << "caught UNO exception: " << OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).getStr() << '\n'; return 1; } return 0; }
pgpVg4xMXoJrV.pgp
Description: PGP signature