I am required to append code to a large scale C++ Windows application that mail merges the contents of an OpenOffice (4.1) Document or an MS Word Document.
I started off by downloading and installing the SDK using the following guide.
http://wiki.services.openoffice.org/wik ... stallation
Next I started to write a test application just to create a new document
The problem I'm having is that I can't "connect" to OpenOffice. It seems that a lot of code example's out there are tied to connecting to Open Office in Unix/Linux
Below is my connection code (copied from the example).
Code: Select all
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0)
{
fprintf(stderr, "WSAStartup failed.\n");
exit(1);
}
OUString sConnectionString(RTL_CONSTASCII_USTRINGPARAM("c:\Program Files (x86)\OpenOffice 4\program\ soffice -accept=socket,host=localhost,port=2083;urp;StarOffice.ServiceManager"));
OUString sUnoIni(RTL_CONSTASCII_USTRINGPARAM("file:///C:/Program Files (x86)/OpenOffice 4/program/uno.ini"));
//OUString sConnectionString(RTL_CONSTASCII_USTRINGPARAM("C:\\Program Files (x86)\\OpenOffice 4\\program\\soffice.exe -accept=socket,host=localhost,port=2002;urp;StarOffice.ServiceManager"));
Reference<XComponentContext> xComponentContext(::cppu::defaultBootstrap_InitialComponentContext(sUnoIni));
/* Gets the service manager instance to be used (or null). This method has
been added for convenience, because the service manager is a often used
object.
*/
Reference<XMultiComponentFactory> xMultiComponentFactoryClient(xComponentContext->getServiceManager());
/* Creates an instance of a component which supports the services specified
by the factory.
*/
Reference<XInterface> xInterface = xMultiComponentFactoryClient->createInstanceWithContext(OUString::createFromAscii("com.sun.star.bridge.UnoUrlResolver" ), xComponentContext);
Reference<XUnoUrlResolver> resolver(xInterface, UNO_QUERY);
// Resolves the component context from the office, on the uno URL given by argv[1].
try
{
xInterface = Reference<XInterface>(resolver->resolve(sConnectionString));
}
catch (Exception& e)
{
printf("Error: cannot establish a connection using '%s':\n %s\n",
OUStringToOString(sConnectionString, RTL_TEXTENCODING_ASCII_US).getStr(),
OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US).getStr());
exit(1);
}
// gets the server component context as property of the office component factory
Reference<XPropertySet> xPropSet(xInterface, UNO_QUERY);
xPropSet->getPropertyValue(OUString::createFromAscii("DefaultContext")) >>= xComponentContext;
// gets the service manager from the office
Reference<XMultiComponentFactory> xMultiComponentFactoryServer(xComponentContext->getServiceManager());
/* Creates an instance of a component which supports the services specified
by the factory. Important: using the office component context.
*/
Reference<XComponentLoader> xComponentLoader(xMultiComponentFactoryServer->createInstanceWithContext(OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop" )),
xComponentContext ), UNO_QUERY );
/* Loads a component specified by an URL into the specified new or existing
frame.
*/
//Reference<XComponent> xComponent = xComponentLoader->loadComponentFromURL(sAbsoluteDocUrl, OUString( RTL_CONSTASCII_USTRINGPARAM("_blank") ), 0, Sequence<::com::sun::star::beans::PropertyValue>());
Reference<XComponent> xComponent = xComponentLoader->loadComponentFromURL(OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/swriter")), OUString( RTL_CONSTASCII_USTRINGPARAM("_blank") ), 0, Sequence<::com::sun::star::beans::PropertyValue>());
// dispose the local service manager
Reference<XComponent>::query(xMultiComponentFactoryClient)->dispose();
// TODO
WSACleanup();
return TRUE;
Is anyone able to provide assistance in how you actually code the service to create/open a document in Windows, let alone Mail Merge. I have no experience in using Open Office & the requirement to get open office to work is an Extremely Very High Priority
Regards
Adam