List Info

Thread: display document in C or C++




display document in C or C++
user name
2007-08-26 12:20:59
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
-- 
View this message in context: http://www.nabble.com/display-doc
ument-in-C-or-C%2B%2B-tf4331642.html#a12336551
Sent from the openoffice - api dev mailing list archive at
Nabble.com.

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org


Re: display document in C or C++
user name
2007-08-26 12:26:14
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.UnoUrlR
esolver"), 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&q
uot;),
		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: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org


Re: display document in C or C++
user name
2007-08-26 12:30:56
Sorry, I forgot that you wanted it to be opened in readonly
mode.
Change this:

// read only
Sequence< PropertyValue > loadProps(1);
loadProps[0] = PropertyValue();
loadProps[0].Name =
OUString::createFromAscii("ReadOnly");
loadProps[0].Value <<= sal_True;

Remember that you should also have a runnig instance of the
soffice
service listening on the appropriate port to do that.

Regards,
	Claudio A. Andreoni

> 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.UnoUrlRe
solver"),
> 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;StarOf
>fice.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&quo
t;),
> 		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: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org


[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )