OpenOffice and OLE

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
borr_1
Super wx Problem Solver
Super wx Problem Solver
Posts: 362
Joined: Wed Mar 07, 2007 8:10 am
Location: Russia, Shakhty

OpenOffice and OLE

Post by borr_1 » Wed Mar 07, 2007 8:15 am

Hi,

I am just looking into using Ole Automation with OO. It seems to work slightly different of MS-Office automation as far as WxWidgets is concerned - because there is a "Service Manager" in between.

Is there anybody out there who has successfully done that and who could give me a hint or a code snippet?

Code: Select all

   wxAutomationObject *OO = new wxAutomationObject();
   OO->CreateInstance(wxT("com.sun.star.ServiceManager"));
This is all what i can.

megabyte
I live to help wx-kind
I live to help wx-kind
Posts: 196
Joined: Tue Dec 07, 2004 8:54 pm
Location: Essen, Germany

Post by megabyte » Fri Mar 09, 2007 9:57 am

I played a little bit with the OpenOffice Automation, but I don't remember any details. I found the following code in my archives. Probably it will help you.

Code: Select all

	wxAutomationObject OO; 
	if (!OO.GetInstance(_T("com.sun.star.ServiceManager"))) {
		if (!OO.CreateInstance(_T("com.sun.star.ServiceManager"))) {
			return false;
		}
	}
	wxVariant vCR = OO.CallMethod(_T("createInstance"), _T("com.sun.star.reflection.CoreReflection"));
	wxAutomationObject CoreReflection(vCR);
	wxVariant vDT = OO.CallMethod(_T("createInstance"), _T("com.sun.star.frame.Desktop"));
	wxAutomationObject DT(vDT);

	wxVariant vPropertyValueTemplate = CoreReflection.CallMethod(_T("forName"), _T("com.sun.star.beans.PropertyValue"));
	wxAutomationObject PropertyValueTemplate(vPropertyValueTemplate);

	OLECHAR* strcreateObject= L"createObject";
	IDispatch *pDisp = (IDispatch *)PropertyValueTemplate.GetDispatchPtr();
	DISPID id;
	HRESULT hr= pDisp->GetIDsOfNames(IID_NULL,&strcreateObject, 1, LOCALE_USER_DEFAULT, &id);

	IDispatch* pdispPropertyValue= NULL;
	VARIANT param1;
	DISPPARAMS dispparams= { &param1, 0, 1, 0};
	VariantClear( &param1);
	param1.vt= VT_DISPATCH | VT_BYREF;
	param1.ppdispVal= &pdispPropertyValue;
	hr= pDisp->Invoke( id, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dispparams, NULL, NULL, 0);
	wxAutomationObject PropertyValue1(pdispPropertyValue);

	PropertyValue1.PutProperty(_T("Name"), _T("Hidden"));
	PropertyValue1.PutProperty(_T("Value"), true);

	CVariantList lst;
	lst.Append(new wxVariant(PropertyValue1.GetDispatchPtr()));
	wxVariant dummy(lst);
	wxVariant vCalc =  DT.CallMethod(_T("loadComponentFromURL"), _T("private:factory/scalc"), _T("_blank"), 0L, dummy);
	wxAutomationObject Calc(vCalc);
	wxVariant ss =  Calc.GetProperty(_T("Sheets"));

borr_1
Super wx Problem Solver
Super wx Problem Solver
Posts: 362
Joined: Wed Mar 07, 2007 8:10 am
Location: Russia, Shakhty

Post by borr_1 » Fri Mar 09, 2007 10:31 am

Thanks, CVariantList - what is it?

phlox81
wxWorld Domination!
wxWorld Domination!
Posts: 1387
Joined: Thu Aug 18, 2005 7:49 pm
Location: Germany
Contact:

Post by phlox81 » Fri Mar 09, 2007 12:31 pm

Looks like a list of wxVariant* to me.
std::vector<wxVariant*> would do the same.

borr_1
Super wx Problem Solver
Super wx Problem Solver
Posts: 362
Joined: Wed Mar 07, 2007 8:10 am
Location: Russia, Shakhty

Post by borr_1 » Fri Mar 09, 2007 12:55 pm

Looks like a list of wxVariant* to me.
std::vector<wxVariant*> would do the same.
No. I try - this not work

Code: Select all

 
       std::vector<wxVariant*> t;
        t.push_back(new wxVariant(PropertyValue1.GetDispatchPtr()));
        wxVariant dummy(&t/*lst*/);
        wxVariant vCalc =  DT.CallMethod(_T("loadComponentFromURL"), _T("private:factory/scalc"), _T("_blank"), 0L, dummy);//error
        wxAutomationObject Calc(vCalc);

borr_1
Super wx Problem Solver
Super wx Problem Solver
Posts: 362
Joined: Wed Mar 07, 2007 8:10 am
Location: Russia, Shakhty

Post by borr_1 » Sat Mar 10, 2007 6:34 am

Code: Select all

wxList lst;
    lst.Append(new wxVariant(PropertyValue1.GetDispatchPtr()));
    wxVariant dummy(lst);
    wxVariant vCalc =  DT.CallMethod(_T("loadComponentFromURL"), _T("private:factory/scalc"), _T("_blank"), 0L, dummy);
  //Calc start
    wxAutomationObject Calc(vCalc);
    wxAutomationObject Sheet;
    //Access Violation(Segmentation Fault)  
    //IDispatch *sh = (IDispatch *)Calc.GetDispatchPtr();
    wxVariant ss = Calc.GetProperty(_T("getSheets"),_T("getByIndex") ,0L, 1);
    //Calc.GetObject(Sheet,wxT("getSheets"));
    //wxVariant ss =  Calc.GetProperty(_T("getSheets"));
Any idya?

borr_1
Super wx Problem Solver
Super wx Problem Solver
Posts: 362
Joined: Wed Mar 07, 2007 8:10 am
Location: Russia, Shakhty

Post by borr_1 » Mon Mar 12, 2007 12:19 pm

Code: Select all

    wxVariant vCalc =  DT.CallMethod(_T("LoadComponentFromURL"), _T("private:factory/scalc"),
                                        _T("_blank"), 0L, dummy);
    WxGrid1->SetCellValue(0,0,"wxAutomationObject Calc(vCalc)");
    wxAutomationObject Calc(vCalc);
    wxVariant ss =  Calc.CallMethod(_T("getSheets"));
    wxAutomationObject Sheets(ss);
    wxVariant vSheet = Sheets.CallMethod(_T("getByIndex"), 0);
    wxAutomationObject Sheet(vSheet);
    wxVariant tmp = Sheet.CallMethod(_T("SetName"),"Test");//work
    wxVariant vc = Sheet.CallMethod(_T("getCellByPosition"),0,0);
    wxAutomationObject Cell(vc);//error - Access violation
Why? Where is my mistake

mountain_man
In need of some credit
In need of some credit
Posts: 1
Joined: Thu Nov 03, 2005 10:30 pm
Contact:

Replacing user fields in Open Office using wxAutomation

Post by mountain_man » Tue Jul 03, 2007 11:47 pm

I'm trying to develop some code in WxWidgets that will replace text in user fields in an Open Office Writer document. (eg I have a date field in the Open Office writer document that I want to insert the date into.

I can sucessfully open the required document using wxAutomationObject.

The code I have for this is

Code: Select all

	wxAutomationObject Oo;                           // Open Office Service Manager
	wxVariant vOoDesktop;                            // Open Office Service Desktop
	wxVariant vOoDocument;                           // Open Office Document
	wxVariant vOoCR;                                 // Open Office Core Refelection
	wxVariant vOoPropertyValueTemplate;              // Open Office Property Value
	wxVariant vOoNamedFieldMasters;                  // Document Named Fields

	// Create the Open Office Service Manager
     Oo.CreateInstance(_T("com.sun.star.ServiceManager"));

	vOoDesktop = Oo.CallMethod(_T("createInstance"), _T("com.sun.star.frame.Desktop"));
	wxAutomationObject OoDesktop(vOoDesktop);

     vOoCR = Oo.CallMethod(_T("createInstance"), _T("com.sun.star.reflection.CoreReflection"));
     wxAutomationObject OoCoreReflection(vOoCR);

     vOoPropertyValueTemplate = OoCoreReflection.CallMethod(_T("forName"), _T("com.sun.star.beans.PropertyValue"));
     wxAutomationObject OoPropertyValueTemplate(vOoPropertyValueTemplate);

     OLECHAR* strcreateObject= L"createObject";
     IDispatch *pDisp = (IDispatch *)OoPropertyValueTemplate.GetDispatchPtr();
     DISPID id;
     HRESULT hr= pDisp->GetIDsOfNames(IID_NULL,&strcreateObject, 1, LOCALE_USER_DEFAULT, &id);

     IDispatch* pdispPropertyValue= NULL;
     VARIANT param1;
     DISPPARAMS dispparams= { &param1, 0, 1, 0};
     VariantClear( &param1);
     param1.vt= VT_DISPATCH | VT_BYREF;
     param1.ppdispVal= &pdispPropertyValue;
     hr= pDisp->Invoke( id, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dispparams, NULL, NULL, 0);
     wxAutomationObject PropertyValue1(pdispPropertyValue);

     PropertyValue1.PutProperty(_T("Name"), _T("Hidden"));
     PropertyValue1.PutProperty(_T("Value"), true); 

     wxList lst;
     lst.Append(new wxVariant(PropertyValue1.GetDispatchPtr()));
     wxVariant dummy(lst);
	vOoDocument = OoDesktop.CallMethod(_T("loadComponentFromURL"), _T("file:///D:\\AW CompuTech\\SOFTWARE_ENGINEERING\\SRC\\CRAB\\TEMPLATES\\diary_summary_all_times.ott"), _T("_blank"), 0L, dummy);
	wxAutomationObject OoDocument(vOoDocument);
I have looked at various code snippets on the Open Office website but can't work out how to translate them into something that will with wxAutomationObject

Has anybody any experience of using wxAutomationObject with OpenOffice?

Post Reply