U++ framework
Do not panic. Ask here before giving up.

Home » Developing U++ » UppHub » Ole Automation [FEATURE REQUEST?]
Re: Ole Automation [FEATURE REQUEST?] [message #21523 is a reply to message #17864] Sun, 24 May 2009 18:36 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3461
Registered: August 2008
Senior Veteran
Change done. Now Automation package is called OfficeAutomation.

I have also included ES/ES translation and I have began with the documentation.

Best regards
Koldo


Best regards
Iñaki
Re: Ole Automation [FEATURE REQUEST?] [message #21532 is a reply to message #21523] Mon, 25 May 2009 10:24 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

Thank you!
Re: Ole Automation [FEATURE REQUEST?] [message #21885 is a reply to message #21399] Tue, 09 June 2009 11:17 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

Hello Koldo!

I found here interesting library for direct manage .xls file.

What is your opinion?

Ion Lupascu (tojocky)

[Updated on: Tue, 09 June 2009 11:17]

Report message to a moderator

Re: Ole Automation [FEATURE REQUEST?] [message #21895 is a reply to message #21885] Tue, 09 June 2009 16:11 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3461
Registered: August 2008
Senior Veteran
Answered here: http://www.ultimatepp.org/forum/index.php?t=msg&goto=218 94&#msg_21894

Best regards
Iñaki
Re: Ole Automation [FEATURE REQUEST?] [message #40796 is a reply to message #21895] Thu, 19 September 2013 16:18 Go to previous messageGo to next message
iST1 is currently offline  iST1
Messages: 107
Registered: August 2013
Experienced Member
In 5485 U++ on 64bit Win7 and Office 2003 after this simple code WINWORD is staying in process list:
	
OfficeDoc word;	
if (word.IsAvailable("Open"))
    word.Init("Open");
else if (word.IsAvailable("Microsoft"))
    word.Init("Microsoft");
	
word.Quit();
Re: Ole Automation [FEATURE REQUEST?] [message #40802 is a reply to message #40796] Fri, 20 September 2013 10:07 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3461
Registered: August 2008
Senior Veteran
Hello iST1

You are right Smile. Problem found and solved. Please update your source tomorrow.


Best regards
Iñaki

[Updated on: Fri, 20 September 2013 10:07]

Report message to a moderator

Re: Ole Automation [FEATURE REQUEST?] [message #40803 is a reply to message #40802] Fri, 20 September 2013 10:13 Go to previous messageGo to next message
iST1 is currently offline  iST1
Messages: 107
Registered: August 2013
Experienced Member
Fine, from here http://www.ultimatepp.org/www$uppweb$nightly$en-us.html?
Is there a list of changes in nightly builds?

[Updated on: Fri, 20 September 2013 10:18]

Report message to a moderator

Re: Ole Automation [FEATURE REQUEST?] [message #40811 is a reply to message #40803] Fri, 20 September 2013 16:41 Go to previous messageGo to next message
Klugier is currently offline  Klugier
Messages: 1119
Registered: September 2012
Location: Poland, Kraków
Senior Contributor
Hello iST1,

The list of changes in upp you can find on following website: code.google.com/p/upp-mirror/source/list.

Sincerely,
Klugier


U++ - one framework to rule them all.

[Updated on: Fri, 20 September 2013 16:42]

Report message to a moderator

Re: Ole Automation [FEATURE REQUEST?] [message #40817 is a reply to message #40811] Sat, 21 September 2013 10:16 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3461
Registered: August 2008
Senior Veteran
Changes uploaded to svn just now.

Best regards
Iñaki
Re: Ole Automation [FEATURE REQUEST?] [message #40841 is a reply to message #40817] Mon, 23 September 2013 06:49 Go to previous messageGo to next message
iST1 is currently offline  iST1
Messages: 107
Registered: August 2013
Experienced Member
I struggle with the problem of embedding Word. This is howto (::SetParent way is the same as in correctly worked http://www.codeproject.com/Articles/3582/Word-Control-for-NE T):
class MainFrm : public TopWindow {
public:
	OfficeSheet sheet;
	OfficeDoc doc;

	MainFrm() {}
	
	void TestExcel() {	
		if (sheet.IsAvailable("Open"))  {
			sheet.Init("Open");
		} else if (sheet.IsAvailable("Microsoft")) {
			sheet.Init("Microsoft");
		}
		
		sheet.AddSheet(true);	
		EmbedAsFrame("XLMAIN");
	}
	
	void TestWord() {	
		if (doc.IsAvailable("Open"))  {
			doc.Init("Open");
		} else if (doc.IsAvailable("Microsoft")) {
			doc.Init("Microsoft");
		}
		
		doc.AddDoc(true);
		EmbedAsFrame("Opusapp");
	}
	
	void EmbedAsFrame(const String &className) {
		HWND embeded = FindWindow(className, NULL);
		::SetParent(embeded, GetHWND());
		 			 	
		Rect r = GetScreenView();
    	        Rect pr = GetScreenClient(GetHWND());
    	
		MoveWindow(embeded, r.left - pr.left, r.top - pr.top, r.Width(), r.Height(), 0);
	}
};

GUI_APP_MAIN
{	
	MainFrm w;
	w.Open();	

	//w.TestExcel();//embeded
#if 1
	w.TestWord();//opened in separated window
#else
        //if we manualy opened some Word, it embeded
	w.EmbedAsFrame("Opusapp");
#endif
	w.Run();

[Updated on: Mon, 23 September 2013 06:56]

Report message to a moderator

Re: Ole Automation [FEATURE REQUEST?] [message #40846 is a reply to message #40841] Mon, 23 September 2013 10:04 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3461
Registered: August 2008
Senior Veteran
Shocked

It is a dirty trick Smile

A version just for Word and included Layout().

There are details to be improved but this could be a base.

#include <OfficeAutomation/OfficeAutomation.h>

using namespace Upp;

class WordFrm : public TopWindow {
public:
	WordFrm() {
		Sizeable().Zoomable();
		embedded = 0;
	}
	void Embed() {	
		if (doc.IsAvailable("Microsoft")) 
			doc.Init("Microsoft");
		
		doc.AddDoc(true);
		String className = "Opusapp";
		embedded = FindWindow(className, NULL);
		::SetParent(embedded, GetHWND());		 			 	
		Layout();
	}
private:
	OfficeDoc doc;
	HWND embedded;
	
	virtual void Layout() {
		if (embedded == 0)
			return;
		Rect r = GetScreenView();
    	Rect pr = GetScreenClient(GetHWND());	
		MoveWindow(embedded, r.left - pr.left, r.top - pr.top, r.Width(), r.Height(), 0);
	}
};

GUI_APP_MAIN
{	
	WordFrm w;
	w.Open();	
	w.Embed();
	w.Run();
}




Best regards
Iñaki
Re: Ole Automation [FEATURE REQUEST?] [message #40848 is a reply to message #40846] Mon, 23 September 2013 10:21 Go to previous messageGo to next message
iST1 is currently offline  iST1
Messages: 107
Registered: August 2013
Experienced Member
I have no another way to do what customer wants:p
For You the code above is working with Word?

What my Word (separately):
http://i018.radikal.ru/1309/20/cc45b9b6008f.png

What my Excel (embedded):
http://s017.radikal.ru/i416/1309/85/98c858e36503.png

I need Word embedded...

[Updated on: Mon, 23 September 2013 10:27]

Report message to a moderator

Re: Ole Automation [FEATURE REQUEST?] [message #40851 is a reply to message #40848] Mon, 23 September 2013 13:17 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3461
Registered: August 2008
Senior Veteran
Hello iST1

The code included works basically well for me with W7-64 Office 2010. The embedded Word moves and resizes with U++ window. However there is some flickering in the Word window frame. The next step could be to remove Word window frame to avoid this.


Best regards
Iñaki
Re: Ole Automation [FEATURE REQUEST?] [message #40854 is a reply to message #40851] Mon, 23 September 2013 15:29 Go to previous messageGo to next message
iST1 is currently offline  iST1
Messages: 107
Registered: August 2013
Experienced Member
I do not have Office > 2003, but can you give me some advice about frame removing? Something like this
int counter = ActiveWindow.Application.CommandBars.Count;
for(int i = 0; i < counter;i++)
ActiveWindow.Application.CommandBars[i].Enabled=false;
}


Also can be Close method added to Automation?
Re: Ole Automation [FEATURE REQUEST?] [message #40855 is a reply to message #40854] Mon, 23 September 2013 16:07 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3461
Registered: August 2008
Senior Veteran
iST1 wrote on Mon, 23 September 2013 15:29

I do not have Office > 2003, but can you give me some advice about frame removing? Something like this
int counter = ActiveWindow.Application.CommandBars.Count;
for(int i = 0; i < counter;i++)
ActiveWindow.Application.CommandBars[i].Enabled=false;
}


Also can be Close method added to Automation?

Hello iST1

I do not know what do you mean with "frame removing".

What would have to do Close()?

This code is better but flickering remains:

#include <OfficeAutomation/OfficeAutomation.h>

using namespace Upp;

class WordFrm : public TopWindow {
public:
	WordFrm() {
		Sizeable().Zoomable();
		embedded = 0;
	}
	void Embed() {	
		if (doc.IsAvailable("Microsoft")) 
			doc.Init("Microsoft");
		
		doc.AddDoc(true);
		embedded = FindWindow("Opusapp", NULL);
		LONG lStyle = GetWindowLong(embedded, GWL_STYLE);
		lStyle &= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU | WS_BORDER | WS_DLGFRAME | WS_SIZEBOX);
		SetWindowLong(embedded, GWL_STYLE, lStyle); 
		LONG lExStyle = GetWindowLong(embedded, GWL_EXSTYLE);
		lExStyle &= ~(WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE);
		SetWindowLong(embedded, GWL_EXSTYLE, lExStyle);			 	
		SetWindowPos(embedded, NULL, 0,0,0,0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
		::SetParent(embedded, GetHWND());		
		Layout();
	}
private:
	OfficeDoc doc;
	HWND embedded;
	
	virtual void Layout() {
		if (embedded == 0)
			return;
		Rect r = GetScreenView();
    	Rect pr = GetScreenClient(embedded);	
		MoveWindow(embedded, r.left - pr.left, r.top - pr.top, r.Width(), r.Height(), TRUE);
	}
	virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam) {
		if (message == WM_SIZE)
			Layout();
		return TopWindow::WindowProc(message, wParam, lParam);
	}
};

GUI_APP_MAIN
{	
	WordFrm w;
	w.Open();	
	w.Embed();
	w.Run();
}



Best regards
Iñaki

[Updated on: Mon, 23 September 2013 16:09]

Report message to a moderator

Re: Ole Automation [FEATURE REQUEST?] [message #40857 is a reply to message #40855] Mon, 23 September 2013 16:31 Go to previous messageGo to next message
iST1 is currently offline  iST1
Messages: 107
Registered: August 2013
Experienced Member
I mean removing all Word/Excel command bars - only document view like in preview mode. Close method need fot close document before open.
Re: Ole Automation [FEATURE REQUEST?] [message #40862 is a reply to message #40857] Tue, 24 September 2013 18:47 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3461
Registered: August 2008
Senior Veteran
Hello iST1

Please post the VBA code to do it and probably it will be rather easy to implement it. There are many forum explaining the details.


Best regards
Iñaki
Re: Ole Automation [FEATURE REQUEST?] [message #40866 is a reply to message #40862] Thu, 26 September 2013 05:53 Go to previous messageGo to next message
iST1 is currently offline  iST1
Messages: 107
Registered: August 2013
Experienced Member
Private Sub Workbook_Open()
    
    For Each cmd In ActiveWindow.Application.CommandBars
        cmd.Enabled = False
    Next
    
End Sub

Thanks in advance
Re: Ole Automation [FEATURE REQUEST?] [message #40871 is a reply to message #40866] Thu, 26 September 2013 16:05 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3461
Registered: August 2008
Senior Veteran
Hello iST1

I have tried it but it does not work in Office 2007 and higher.

It is due to the new Office menus (called "Fluent") work in a completely different way.


Best regards
Iñaki
Re: Ole Automation [FEATURE REQUEST?] [message #40872 is a reply to message #40871] Thu, 26 September 2013 17:47 Go to previous messageGo to next message
iST1 is currently offline  iST1
Messages: 107
Registered: August 2013
Experienced Member
This is strange, because .net code here work perfectly with Word 2007 and use the analogue of the VBA above code + SetParent method.
Re: Ole Automation [FEATURE REQUEST?] [message #40875 is a reply to message #40872] Fri, 27 September 2013 11:12 Go to previous messageGo to next message
iST1 is currently offline  iST1
Messages: 107
Registered: August 2013
Experienced Member
Installed: MS Office 2007 and Open Office 4.

In #if 1 code opened MS Doc + MS Excel
In #if 0 code (in sub thread) opened MS Doc + Open Calc

Why MS Excel inavaylable in thread and how to set the priority for Microsoft? Thread used to preinit costly loading.

class OfficeTest : public TopWindow {
public:
	typedef OfficeTest CLASSNAME;
	
	OfficeTest() {
#if 1
		Check();
#else
		Thread().Start(THISBACK(Check));
#endif
	}
	
	void Check() {
 		if (sheet.IsAvailable("Microsoft")) {
			sheet.Init("Microsoft");
			sheet.AddSheet(true);
		} else if (sheet.IsAvailable("Open"))  {
			sheet.Init("Open");
			sheet.AddSheet(true);
		} 
				
		if (doc.IsAvailable("Microsoft")) {
			doc.Init("Microsoft");
			doc.AddDoc(true);
		} else if (doc.IsAvailable("Open")) {
			doc.Init("Open");
			doc.AddDoc(true);
		} 
	}
	
private:
	OfficeSheet sheet;
	OfficeDoc doc;
};

GUI_APP_MAIN
{	
	OfficeTest().Run();
}

[Updated on: Fri, 27 September 2013 11:25]

Report message to a moderator

Re: Ole Automation [FEATURE REQUEST?] [message #40876 is a reply to message #40875] Fri, 27 September 2013 11:32 Go to previous messageGo to next message
iST1 is currently offline  iST1
Messages: 107
Registered: August 2013
Experienced Member
What is more, if we exchange the order of testing Excel
                if (sheet.IsAvailable("Open"))  {
			sheet.Init("Open");
			sheet.AddSheet(true);
		} else if (sheet.IsAvailable("Microsoft")) {
			sheet.Init("Microsoft");
			sheet.AddSheet(true);
		}

opened MS Excel instead Open Calc Shocked
Re: Ole Automation [FEATURE REQUEST?] [message #40884 is a reply to message #40872] Mon, 30 September 2013 08:17 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3461
Registered: August 2008
Senior Veteran
iST1 wrote on Thu, 26 September 2013 17:47

This is strange, because .net code here work perfectly with Word 2007 and use the analogue of the VBA above code + SetParent method.

Hello iST1

I have tried that code and it works well, although as I previously reported it does not remove the menus.

You can see the explanation here ( http://social.msdn.microsoft.com/Forums/office/en-US/c329f3e 5-0e25-44a2-8b07-1182d428de37/how-to-disable-menu-bar-in-wor d-2007-programmatically-in-c). In summary:

Word 2007 (and later versions) no longer use the CommandBars (Menu and toolbars) for the UI. This was changed, for various reasons, not least of which to explicitly prevent applications running out-of-process from interfering in the application's UI. Among other considerations, this is a security measure to prevent outside apps from leveraging the Office object models for "bad intentions".

So the short answer to your request is that there is no way for your app to affect an Office UI that implements the Ribbon (Office Fluent UI). The Ribbon can be defined only by RibbonXML embedded in an Office document, or that is part of a COM Add-in (implements the IDT2Exensibility interface).

Possibly, you could create a custom template that contains a RibbonXML with startFromScratch attribute set to True. That will reduce available Ribbon commands to a minimum. It's not possible, however, to remove all commands from the UI. Certain ones in Office 2007 are always enabled, in order to allow the user to have final control over the Office environment.




Best regards
Iñaki
Re: Ole Automation [FEATURE REQUEST?] [message #40885 is a reply to message #40876] Mon, 30 September 2013 08:24 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3461
Registered: August 2008
Senior Veteran
iST1 wrote on Fri, 27 September 2013 11:32

What is more, if we exchange the order of testing Excel
                if (sheet.IsAvailable("Open"))  {
			sheet.Init("Open");
			sheet.AddSheet(true);
		} else if (sheet.IsAvailable("Microsoft")) {
			sheet.Init("Microsoft");
			sheet.AddSheet(true);
		}

opened MS Excel instead Open Calc Shocked

Hello iST1

OfficeAutomation is not designed to be multithreaded.

If you really need that feature I will try to implement it.


Best regards
Iñaki
Re: Ole Automation [FEATURE REQUEST?] [message #40886 is a reply to message #40885] Mon, 30 September 2013 08:57 Go to previous messageGo to next message
iST1 is currently offline  iST1
Messages: 107
Registered: August 2013
Experienced Member
Since application works with collection of Word/Excel and IsAvailable method a costly by time, i don't call him in main GUI thread. I decided to open every files in single form (FilePreviewCmd in code). For this i calling:
	Single<FilePreviewCmd>().StartInit();

If there is an alternative way, I'll take it.
void
FilePreviewCmd::StartInit()
{
	//CheckOfficePlugins(false);//sync
	thread_.Run(THISBACK1(CheckOfficePlugins, true));//acync
}
	
void 
FilePreviewCmd::CheckOfficePlugins(bool preinit)
{
	isXlsOpen = sheet.IsAvailable("Open");
	isXlsMS = sheet.IsAvailable("Microsoft");
	if (!isXlsMS)
		isXlsOpen = sheet.IsAvailable("Open");
	
	isDocMS = doc.IsAvailable("Microsoft");
	if (!isDocMS)
		isDocOpen = doc.IsAvailable("Open");

	if (preinit)
		PostCallback(THISBACK(InitOfficePlugins));
	else 
		InitOfficePlugins();
}
	
void 
FilePreviewCmd::InitOfficePlugins()
{
 	if (isXlsMS) {
		sheet.Init("Microsoft");
	} else if (isXlsOpen)  {
		sheet.Init("Open");
	} 
	
	if (isDocMS) {
		doc.Init("Microsoft");
	} else if (isDocOpen) {
		doc.Init("Open");
	} 
	 		
	TopWindow::Open();
}
Re: Ole Automation [FEATURE REQUEST?] [message #40887 is a reply to message #40886] Mon, 30 September 2013 10:39 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3461
Registered: August 2008
Senior Veteran
Hello iST1

It seems that main thread calls a thread with CheckOfficePlugins() that calls another thread with InitOfficePlugins() that opens main window.

Am I right?


Best regards
Iñaki
Re: Ole Automation [FEATURE REQUEST?] [message #40888 is a reply to message #40887] Mon, 30 September 2013 10:55 Go to previous messageGo to next message
iST1 is currently offline  iST1
Messages: 107
Registered: August 2013
Experienced Member
Yes, except that FilePreviewCmd::InitOfficePlugins opens FilePreviewCmd child window. StartInit called from main window. InitOfficePlugins introduced as a main thread procedure, then otherwise crushes occur and i don't know why.
Re: Ole Automation [FEATURE REQUEST?] [message #40892 is a reply to message #40888] Tue, 01 October 2013 08:31 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3461
Registered: August 2008
Senior Veteran
Hello iST1

InitOfficePlugins() seems to be open in a thread so calling TopWindow::Open() will be dangerous.

I imagine that you would like to launch from the main thread a thread doing the inits and after that to run from the main thread the automation, without any additional thread.

Is not it?


Best regards
Iñaki
Re: Ole Automation [FEATURE REQUEST?] [message #40894 is a reply to message #40892] Tue, 01 October 2013 10:52 Go to previous messageGo to next message
iST1 is currently offline  iST1
Messages: 107
Registered: August 2013
Experienced Member
Oh, i have not noticed what InitOfficePlugins with Open can be used after thread_.Wait() in the main thread, but thread_.Run(THISBACK1(CheckOfficePlugins, true)) is needed for speedup.

[Updated on: Tue, 01 October 2013 11:07]

Report message to a moderator

Re: Ole Automation [FEATURE REQUEST?] [message #41080 is a reply to message #17864] Wed, 30 October 2013 08:52 Go to previous message
keltor is currently offline  keltor
Messages: 73
Registered: February 2012
Member
Hello,

sorry to hijack the thread, I just want to ask something that I think is most relevant here than anywhere else. Does anybody know how to create an ActiveX control with U++ so that it can be embedded, for instance, in a Word document? For instance, how to modify the Scatter control so that one can display, and possibly scroll around, graphs inside Word or PowerPoint or any other COM server.

Thanks,

Kel
Previous Topic: MAPIEx works with MinGW
Next Topic: [Controls4U] IE shows script errors
Goto Forum:
  


Current Time: Sun Oct 04 17:37:38 GMT+2 2026

Total time taken to generate the page: 0.01788 seconds