Hello Ariel, 

many thanks for your code-snippet...

That was it, what I need;-)

Works fine...

Best regards from Germany

Andre


Am Donnerstag, 7. Februar 2008 23:09 schrieb Ariel Constenla-Hagle:
> Hello Andre,
>
> Andre Heine escribió:
> > Hello all,
> >
> > in oobasic can I set the "SetOptimalColumnWidth" on selected
> > cells/columns.
>
> I guess you were using the dispatch with the command URL
> ".uno:SetOptimalColumnWidth", because there is no method named
> setOptimalColumnWidth().
>
> In fact there is the property "OptimalWidth" in the service
> css.table.TableColumn.
>
> > Know someone the property name for the C++ API?
>
> there is only *one* OOo API, with different language bindings. SO that
> the services and interfaces are the same, i.e. language independent.
>
> > Any hints?
>
> the following works, but is pure API calls, NO dispatching at all
> (because I don't like it at all ;-) ). See if you can modify it to fit
> your needs:
>
> #include <iostream>
>
> #include <cppuhelper/bootstrap.hxx>
> #include <rtl/ustring.hxx>
>
> #include <com/sun/star/beans/PropertyValue.hpp>
> #include <com/sun/star/beans/XPropertySet.hpp>
> #include <com/sun/star/container/XIndexAccess.hpp>
> #include <com/sun/star/frame/XComponentLoader.hpp>
> #include <com/sun/star/lang/XMultiComponentFactory.hpp>
> #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
> #include <com/sun/star/sheet/XSpreadsheets.hpp>
> #include <com/sun/star/sheet/XSpreadsheet.hpp>
> #include <com/sun/star/table/XCell.hpp>
> #include <com/sun/star/table/XColumnRowRange.hpp>
> #include <com/sun/star/table/XTableColumns.hpp>
> #include <com/sun/star/uno/XComponentContext.hpp>
>
> using namespace std;
> using namespace rtl;
> using namespace com::sun::star::beans;
> using namespace com::sun::star::container;
> using namespace com::sun::star::frame;
> using namespace com::sun::star::lang;
> using namespace com::sun::star::sheet;
> using namespace com::sun::star::table;
> using namespace com::sun::star::uno;
>
>
> 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 Calc document
>               Reference< XSpreadsheetDocument > rSpreadsheetDocument (
>                       rComponentLoader->loadComponentFromURL(
>                       OUString( RTL_CONSTASCII_USTRINGPARAM( 
> "private:factory/scalc" ) ),
>                       OUString( RTL_CONSTASCII_USTRINGPARAM( "_blank" ) ),
>                       0,
>                       Sequence < ::com::sun::star::beans::PropertyValue >() 
> ), UNO_QUERY );
>
>           // get the collection of sheets in the document
>               Reference< XSpreadsheets > rSheets = 
> rSpreadsheetDocument->getSheets();
>
>               // XIndexAccess to get an spreadsheet by index
>               Reference< XIndexAccess > rIndexedSheets( rSheets, UNO_QUERY );
>
>               // get the first sheet (index == 0)
>               Reference< XSpreadsheet > rSpreadsheet( 
> rIndexedSheets->getByIndex(
> sal_Int32( 0 ) ), UNO_QUERY );
>
>               // query the sheet's XColumnRowRange to access the collections 
> of
> columns and rows of the sheet
>               Reference< XColumnRowRange > rColumnRowRange ( rSpreadsheet, 
> UNO_QUERY );
>
>               // get the collection of columns
>               Reference< XTableColumns > rTableColumns = 
> rColumnRowRange->getColumns();
>
>               // get the first column (index == 0), and query its 
> XPropertySet to
> cahnge its properties
>               Reference< XPropertySet > rPropertySet ( 
> rTableColumns->getByIndex(
> sal_Int32( 0 ) ), UNO_QUERY );
>
>               // get the cell named A1
>               Reference< XCell > rCellA1 = rSpreadsheet->getCellByPosition(
> sal_Int32( 0 ),  sal_Int32( 0 ) );
>
>               // set a very long text
>               rCellA1->setFormula( OUString::createFromAscii(
>
> "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
>aaaaaaaaaaaaaaaaaaaa") );
>
>               cout << "Press ENTER to set the column property  OptimalWidth 
> to true";
>               cin.get();
>               cout << endl;
>
>               // change the property OptimalWidth, so that the column is as 
> width as
> the text inside the cell
>               rPropertySet->setPropertyValue(
> OUString::createFromAscii("OptimalWidth"), Any( sal_True ) );
>
>               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;
> }

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to