Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » UppHub » OfficeAutomation - Update Requests
OfficeAutomation - Update Requests [message #34738] Fri, 09 December 2011 10:32 Go to previous message
ratah is currently offline  ratah
Messages: 107
Registered: July 2010
Experienced Member
Hello Koldo,

I have 2 modifications I want you insert in the OfficeAutomation version.

The first one is about the bad process killing: EXCEL remains in memory even if my executable is closed.
So I use a little process killer function. Do not forget to include tlhelp32.h

#include <Core/Core.h>
#include <tlhelp32.h>

using namespace Upp;

#include <Functions4U/Functions4U.h>
#include <OfficeAutomation/OfficeAutomation.h>

BOOL KillProcessByName(char *szProcessToKill)
{
	HANDLE hProcessSnap;
	HANDLE hProcess;
	PROCESSENTRY32 pe32;
	DWORD dwPriorityClass;

	hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);  // Takes a snapshot of all the processes

	if(hProcessSnap == INVALID_HANDLE_VALUE){
		return( FALSE );
	}

	pe32.dwSize = sizeof(PROCESSENTRY32);

	if(!Process32First(hProcessSnap, &pe32)){
		CloseHandle(hProcessSnap);
		return( FALSE );
	}

	do{
		if(!strcmp(pe32.szExeFile,szProcessToKill)){    //  checks if process at current position has the name of to be killed app
			hProcess = OpenProcess(PROCESS_TERMINATE,0, pe32.th32ProcessID);  // gets handle to process
			TerminateProcess(hProcess,0);   // Terminate process by handle
			CloseHandle(hProcess);  // close the handle
		}
	}while(Process32Next(hProcessSnap,&pe32));  // gets next member of snapshot

	CloseHandle(hProcessSnap);  // closes the snapshot handle
	return( TRUE );
}


CONSOLE_APP_MAIN
{
	
	try
	{
	// TEST XLS
		
		OfficeSheet sheet;
			
		bool openAvailable = sheet.IsAvailable("Open");
		bool microsoftAvailable = sheet.IsAvailable("Microsoft");
		
		if(!openAvailable && !microsoftAvailable)
		{
			throw Exc("MS Office n'est pas pret, le programme ne peut pas lire le fichier Excel!!");	
		}
		
		if (openAvailable) 
		{
			sheet.Init("Open");
		}
		else if (microsoftAvailable) 
		{
			sheet.Init("Microsoft");
		}
			
		String ficXLS = ConfigFile("test.xls");
		
		if (!sheet.OpenSheet(ficXLS, false)) 
		{
			sheet.AddSheet(true);
			
			if(sheet.InsertTab("My new tab"))
				sheet.SetValue(3, 21, "Hello");
			
			sheet.SaveAs(ficXLS, "xls");
			/*sheet.Quit();*/
			//sheet.End();  -> HOW DO I USE THIS ????
			sheet.Quit();
			
// BUG le processus EXCEL n'est pas déchargé totalement du mémoire!!!

			// PromptOK(AsString(LocalProcess("EXCEL").IsRunning()));  -> DOES NOT WORK AS I WANT SO I USE ANOTHER FUNCTION
			
			KillProcessByName("EXCEL.EXE");				
		}
		else
		{
			Cout() << "test.xls already exists!!";
		}

	}
	catch(Exc &e)
	{
		Cout() << e;	
	}

}



The second one concern OfficeSheet test of availability ( bool microsoftAvailable = sheet.IsAvailable("Microsoft")Wink
It shows the messages below if MS Office is not installed in the computer test. Could you remove these messages please.
index.php?t=getfile&id=3575&private=0

I compiled with the nightbuilt Version 4140 of TheIDE, do not consider these requests if corrections are yet done.

Best regards,

Lova Tahina
  • Attachment: message12.JPG
    (Size: 21.28KB, Downloaded 824 times)
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: OpenCL
Next Topic: Themes / Theme resets to host default when Autohide taskbar done
Goto Forum:
  


Current Time: Fri Apr 19 22:41:23 CEST 2024

Total time taken to generate the page: 0.06069 seconds