Hi k.misha,

On Wed, Apr 10, 2013 at 01:00:58PM +0300, k.misha wrote:
> Hi! 
> I have a code:
> <неи<неиReference< ::com::sun::star::sheet::XSpreadsheetDocument > 
> xSpreadsheetDocument(xCalcComponent, UNO_QUERY);
> <неиReference< ::com::sun::star::sheet::XSpreadsheets > xSpreadsheets = 
> xSpreadsheetDocument->getSheets();
> <неиReference< ::com::sun::star::container::XNameAccess > 
> xNameAccess(xSpreadsheets, UNO_QUERY);
> <неи<неиSequence< OUString > sElementNames = xNameAccess->getElementNames();
> <неи<неиI want to get a list of sheets in document. 
> How I can see it using printf("%s", variable)?<неи<неиThanks!<неи

(side note: your mail client, Microsoft Office Outlook 12.0, seems to
mess with the format; at least gmail shows your mails in a single line,
almost impossible to read)

Iterate over the css::uno::Sequence, and get the null terminated string
from the rtl::OUString with rtl::OUStringToOString
http://www.openoffice.org/api/docs/cpp/ref/names/rtl/o-ustring.hxx.html#OUStringToOString-1421

Alternatively, you can use operator<< with std::ostream instead of C's
printf, as in the example attached.


Regards
-- 
Ariel Constenla-Haile
La Plata, Argentina
/**************************************************************
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 *************************************************************/

#include <sal/main.h>
#include <rtl/ustring.hxx>
#include <rtl/ustrbuf.hxx>
#include <com/sun/star/uno/Sequence.hxx>

#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>

using rtl::OUString;
using com::sun::star::uno::Sequence;
using namespace std;


std::ostream &operator<<( std::ostream &rout, const rtl::OUString &rStr );

template< class TElementType >
class SequenceAsVector : public ::std::vector< TElementType >
{
    public:
        typedef typename ::std::vector< TElementType >::const_iterator 
const_iterator;

        SequenceAsVector()
        {}

        ~SequenceAsVector()
        {}

        SequenceAsVector( const Sequence< TElementType > &lSource )
        {
            ( *this ) << lSource;
        }

        void operator<<( const Sequence< TElementType > &lSource )
        {
            this->clear();

            sal_Int32 c = lSource.getLength();
            const TElementType *pSource = lSource.getConstArray();

            for ( sal_Int32 i = 0; i < c; ++i )
                this->push_back( pSource[i] );
        }

        void operator>>( Sequence< TElementType > &lDestination ) const
        {
            sal_Int32 c = ( sal_Int32 )this->size();
            lDestination.realloc( c );
            TElementType *pDestination = lDestination.getArray();

            sal_Int32 i = 0;
            for ( typename std::vector<TElementType>::const_iterator pThis  = 
this->begin();
                    pThis != this->end()  ;
                    ++pThis           )
            {
                pDestination[i] = *pThis;
                ++i;
            }
        }

        const Sequence< TElementType > getAsConstList() const
        {
            Sequence< TElementType > lDestination;
            ( *this ) >> lDestination;
            return lDestination;
        }
};


struct PrintOUStringSeq
        : public std::unary_function< const OUString &, void >
{
        PrintOUStringSeq()
            : m_nCount( 0 )
        {}

        void operator()( const rtl::OUString &rStr )
        {
            std::cout << '[' << m_nCount << "] " << rStr << '\n';
            ++m_nCount;
        }
    private:
        int m_nCount;
};

ostream &
operator<<( ostream &rout, const OUString &rStr )
{
    return rout << rtl::OUStringToOString( rStr, RTL_TEXTENCODING_UTF8 
).getStr( );
}


SAL_IMPLEMENT_MAIN_WITH_ARGS( argc, argv )
{

    Sequence< OUString > aSeq( 4 );
    aSeq[0] = OUString( RTL_CONSTASCII_STRINGPARAM( "文泉驛等寬微米黑" ), 
RTL_TEXTENCODING_UTF8 );
    aSeq[1] = OUString( RTL_CONSTASCII_STRINGPARAM( "文泉驛微米黑" ), 
RTL_TEXTENCODING_UTF8 );
    aSeq[2] = OUString( RTL_CONSTASCII_STRINGPARAM( "文泉驛正黑" ), 
RTL_TEXTENCODING_UTF8 );
    aSeq[3] = OUString( RTL_CONSTASCII_STRINGPARAM( "文泉驛點陣正黑" ), 
RTL_TEXTENCODING_UTF8 );

    SequenceAsVector< OUString > vec( aSeq );

    std::for_each( vec.begin(), vec.end(), PrintOUStringSeq() );

    cout << "Press ENTER to exit...";
    cin.get();

    return 0;
}

Attachment: pgptMSYtQPbg3.pgp
Description: PGP signature

Reply via email to