LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

CVI - Parcours des fichiers excel ouverts "dans windows"

Solved!
Go to solution

Bonjour,

 

Je travaille sur un projet en CVI (8.0), qui doit traiter des fichiers Excel.

Le problème c'est que mon logiciel ne maitrise pas le fichier qui est ouvert : son nom et son emplacement ne sont pas connus par le programme.

 

Mon idée est donc de parcourir les fichiers excel ouverts, pour vérifier la présence de chaines de caractères caractéristiques dans certaines cases.

Par contre, je n'arrive pas à trouver dans l'API Excel les fonctionns qui me permettent de parcourir ces fichiers.

 

Mon idée serait par exemple  :

 

 

 

Lancer Excel (se connecter, avec le Excel_ActiveApp )
POUR chaque fichier ouvert FAIRE
     Lire contenu case 'A1'
     Si contenu == "toto" ALORS
        // C'est mon fichier
    SINON
        // C'est pas mon fichier 
    FIN SI
FIN POUR

 

J'ai essayé de chercher avec

Microsoft Excel 14.0 Object Library

et

Microsoft Excel 9.0 Object Library

 

je n'ai pas trouvé.

 

Je suis donc à la recherche d'aide,

 

Merci par avance,

Cédric.

0 Kudos
Message 1 of 4
(3,080 Views)
Solution
Accepted by topic author cedric_b

I find the solution here :

http://www.theusenetarchive.com/usenet-message-cvi-and-excel-help-11429335.htm

 

 

 

This modified callback in excel2000dem sample project lists all opened files in Excel:

//----------------------------------------------------------------------------
// ConnectApp
//----------------------------------------------------------------------------
int CVICALLBACK ConnectApp (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
long ExcelWorkbooksCount;
HRESULT error = 0;
int i;
char *ExcelWorkbookName;

switch (event)
{
case EVENT_COMMIT:
// Launch App
// Connect to existing application if available
SetWaitCursor (1);
error = Excel_ActiveApp (NULL, 1, LOCALE_NEUTRAL, 0, &ExcelAppHandle);
SetWaitCursor (0);
if (error<0)
goto Error;

// Make App Visible
error = Excel_SetProperty (ExcelAppHandle, NULL, Excel_AppVisible, CAVT_BOOL, appVisible?VTRUE:VFALSE);
if (error<0)
goto Error;

// Get number of open files
error = Excel_GetProperty (ExcelAppHandle, NULL, Excel_AppWorkbooks, CAVT_OBJHANDLE, &ExcelWorkbooksHandle);
if (error < 0) goto Error;
error = Excel_GetProperty (ExcelWorkbooksHandle, NULL, Excel_WorkbooksCount, CAVT_LONG, &ExcelWorkbooksCount);
if (error < 0) goto Error;

// Iterate through files and get file name
for (i = 1; i <= ExcelWorkbooksCount; i++) {
error = Excel_WorkbooksItem (ExcelWorkbooksHandle, NULL, CA_VariantInt(i), &ExcelWorkbookHandle);
if (error<0)
goto Error;
error = Excel_GetProperty (ExcelWorkbookHandle, NULL, Excel_WorkbookName, CAVT_CSTRING, &ExcelWorkbookName);
// Print file name
DebugPrintf ("Workbook %d: %s\n", i, ExcelWorkbookName);
// Free resources
ClearObjHandle (&ExcelWorkbookHandle);
CA_FreeMemory (ExcelWorkbookName);
if (error<0)
goto Error;
}

UpdateUIRDimming(panelHandle);
MakeApplicationActive ();
excelLaunched = 0;
break;
}
return 0;
Error:
if (error < 0)
ReportAppAutomationError (error);

return 0;
}

 

0 Kudos
Message 2 of 4
(3,046 Views)

well, actually the correct reference is this one

0 Kudos
Message 3 of 4
(3,042 Views)

ok, i did not found it when i need it.

thanks.

0 Kudos
Message 4 of 4
(3,037 Views)