Hello

In order to run this code you have to run cppuhelper in an appropriate manner 
to get the
headers for the OO API. You can find how to do this at http://api.openoffice.org
It isn't that easy to learn C++ OpenOffice API programming, so I suggest to 
spend a
couple of days in learning the official tutorials (you can find them on the OO 
website).

Good luck for your OO trip.

Regards,
        Claudio A. Androeni

#include <cppuhelper/bootstrap.hxx>

#include <com/sun/star/bridge/XUnoUrlResolver.hpp>
#include <com/sun/star/uno/XInterface.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/frame/XComponentLoader.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/document/XExporter.hpp>
#include <com/sun/star/document/XFilter.hpp>
#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
#include <com/sun/star/drawing/XDrawPages.hpp>
#include <com/sun/star/drawing/XDrawPage.hpp>
#include <com/sun/star/document/XMimeTypeInfo.hpp>

using namespace std;

using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
using namespace com::sun::star::bridge;
using namespace com::sun::star::frame;
using namespace com::sun::star::beans;
using namespace com::sun::star::document;
using namespace com::sun::star::drawing;

using namespace rtl;
using namespace cppu;

int main()
{
        //create the initial soffice component
        Reference<XComponentContext> xComponentContext = 
defaultBootstrap_InitialComponentContext();
        
        //retrieve the service manager
        Reference<XMultiComponentFactory> xServiceManager = 
xComponentContext->getServiceManager();
        
        //instantiate the service
        Reference<XInterface> xInstance = 
xServiceManager->createInstanceWithContext(
        OUString::createFromAscii("com.sun.star.bridge.UnoUrlResolver"), 
xComponentContext
        );
        
        //obtain the resolver interface
        Reference<XUnoUrlResolver> xResolver(xInstance, UNO_QUERY);
        if(!xResolver.is()) cerr << "ERROR! can't instantiate resolver" << endl;
        
        try
        {
                //resolve the UNO URL
                Reference<XInterface> xInterface = xResolver->resolve(
                
OUString::createFromAscii("uno:socket,host=127.0.0.1,port=8100;urp;StarOffice.ServiceManager")
                );
                if(!xInterface.is()) cerr << "ERROR! can't instantiate 
interface" << endl;
                
                //query for the base scripting interface
                Reference<XMultiServiceFactory> xServiceManager(xInterface, 
UNO_QUERY);
                if(!xServiceManager.is()) cerr << "ERROR! can't instantiate 
service manager" << endl;
                
                /*
                //retreive all the available services for the current soffice 
UNO instance
                Sequence<OUString> services = 
xServiceManager->getAvailableServiceNames();
                for(int i=0; i<services.getLength(); i++)
                {
                        OString buffer = OUStringToOString(services[i], 
RTL_TEXTENCODING_ASCII_US );
                        cout << buffer.pData->buffer << endl;
                }
                */
                
                //create a new instance of a desktop, the base document handler
                Reference<XInterface> xDesktop = 
xServiceManager->createInstance(
                OUString::createFromAscii("com.sun.star.frame.Desktop"));
                if(!xDesktop.is()) cerr << "ERROR! no Desktop!" << endl;
                
                //get a component loader
                Reference< XComponentLoader > xComponentLoader (xDesktop, 
UNO_QUERY);
                if(!xComponentLoader.is()) cerr << "ERROR! can't get a 
component loader!" << endl;
                
                // we have to set no property
                Sequence< PropertyValue > loadProps(0);
                
                // obtain the abstraction of the document
                Reference<XComponent> xComponent = 
xComponentLoader->loadComponentFromURL(
                OUString::createFromAscii("file:///home/you/doc.xls"),
                OUString::createFromAscii("_blank"),
                0,
                loadProps);
                if(!xComponent.is()) cerr << "ERROR! can't load document!" << 
endl;

On Sunday 26 August 2007 19:20:59 frank111981 wrote:
> 
> In a C or C++ program I have to open a open Office document to show it to the
> user in read only way. I hope that there is an API function that can help me
> by calling the Open Office suite and open the file but I don't find it.
> Could you help me?
> If you know a solution to do that in Java it can be useful anyway.
> 
> Thanks a lot
> Frank


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

Reply via email to