|
|
Home » Developing U++ » UppHub » OfficeAutomation - Update Requests
OfficeAutomation - Update Requests [message #34738] |
Fri, 09 December 2011 10:32 |
|
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")
It shows the messages below if MS Office is not installed in the computer test. Could you remove these messages please.
I compiled with the nightbuilt Version 4140 of TheIDE, do not consider these requests if corrections are yet done.
Best regards,
Lova Tahina
|
|
|
|
|
|
|
|
|
|
|
Goto Forum:
Current Time: Wed Dec 04 15:32:42 CET 2024
Total time taken to generate the page: 0.01654 seconds
|
|
|