LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Excel not launching using excelreport.fp

Hello,

 

I have an odd bug. I am using excelreport.fp to open an Excel application for reading.

This works 95 percent of the time, except every now and then Excel will freeze or hang up.

I have to close my application and manually terminate the Excel process in order to recover.

I found the issue by stoping during debug and the code is stuck on Excel function.

 

I am trying to reproduce the error now, but it decided to work today. But I know the hang up is in one of these lines from a past debug:

 

    ExcelRpt_ApplicationNew (VFALSE, &applicationHandle);    
    ExcelRpt_WorkbookOpen (applicationHandle, supp_language.filepath, &workbookHandle);
    ExcelRpt_GetWorksheetFromIndex (workbookHandle, 1, &worksheetHandle);

 

I am pretty sure the issue occurs and freezes on WorkbookOpen, but since I can't repeat it on demand I can't be 100% sure.

 

Anyone else experience issues opening Excel using excelreport.fp?

Am I perhaps just using Excel before it is ready?

Is there an Excel timeout to generate a failure so that I am not stuck in an infinite loop?

 

Thanks.

Veni Vidi Duci
0 Kudos
Message 1 of 6
(4,151 Views)

Hello, I'm not using excel report instrument but rather Excel directly with excel2000 instrument (which is the base on top of which excel report is built).

I saw this happening several times before and I have found that it is strictly related to some handle not properly closed / disposed off before terminating working with Excel: double check that all handles and objects are properly handled in every condition before closing Excel.

As a general rule, I took the habit of disposing of every object immediately after using it, even if I could be reusing it later: I know I can be adding some extra work Smiley Frustrated but I avoid the hassle of keeping track of open objects in all program functions I use Excel in. My code is full of  ClearObjHandle and CA_VariantClear instructions but no Excel freezing happens now. Smiley Happy

 

Based on your description, I can imagine that you have some piece of code that is not executed always but keeps some object allocated: if you can delimit the situation in which freezes happen and see which operations have been executed you could probably get the object left behind.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 6
(4,138 Views)

I looked over my code and I don't think it's a handle that is being left open.

I am waiting for the code to crash again so I can identiy more, but like I said it occurs randomly.

 

I use all the excel functions in a single function, and I end that function with the following commands:

 

    if(workbookHandle)
        ExcelRpt_WorkbookClose (workbookHandle, 0);
    if(applicationHandle)
        ExcelRpt_ApplicationQuit (applicationHandle);
 
    CA_DiscardObjHandle (applicationHandle);
    CA_DiscardObjHandle (workbookHandle);
    CA_DiscardObjHandle (worksheetHandle);

 

 

I edited out the useless bits, my function basically works like this:

 

CAObjHandle applicationHandle = 0;
CAObjHandle workbookHandle = 0;
CAObjHandle worksheetHandle = 0;

 

    ExcelRpt_ApplicationNew (VFALSE, &applicationHandle);
       
    //Open the XLSX Workbook
    ExcelRpt_WorkbookOpen (applicationHandle, filepath, &workbookHandle);
   
    //Get the Worksheet
    ExcelRpt_GetWorksheetFromIndex (workbookHandle, 1, &worksheetHandle);


   // I have a for loop to check the cell values I need        
    ExcelRpt_GetCellValue (worksheetHandle, search, CAVT_CSTRING, &buffer);

   //Then I close the function

    
    if(workbookHandle)
        ExcelRpt_WorkbookClose (workbookHandle, 0);
    if(applicationHandle)
        ExcelRpt_ApplicationQuit (applicationHandle);
 
    CA_DiscardObjHandle (applicationHandle);
    CA_DiscardObjHandle (workbookHandle);
    CA_DiscardObjHandle (worksheetHandle);

 

I suppose I can try modifying it to use the Excel2000 instead. It's worth a shot.

Veni Vidi Duci
0 Kudos
Message 3 of 6
(4,124 Views)

I see. As I told you I am not using the excel report instrument: since I only interface to Excel to import/export data I decided to use the basic functionality instead of the more complete instrument. My suggestion derived from that experience in the hope that could be applied to excel report as well. For what I'm seeing there seems to be no evident reason for the erratical behaviour based on the code you posted. The only additional suggestion I can think of could be to explicitly dispose of the memory allocated in ExcelRpt_GetCellValue if you are not doing this already (use CA_FreeMemory).



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 6
(4,108 Views)

Ah, I see I completely overlooked the free memory.

I didn't even think of its since I was passing a character of a defined size.

 

I will run some more tests and see if the error pops back up.

Thanks.

Veni Vidi Duci
0 Kudos
Message 5 of 6
(4,094 Views)

OK, so the error cropped up again.

Here is what I know.

The program hangs up in ExcelPrt_WorkbookOpen. Specifically, in the bolded command of excelreport.c.

Hopefully this makes sense to someone.

 

 

HRESULT CVIFUNC ExcelRpt_WorkbookOpen(CAObjHandle applicationHandle,

const char *fileName,
         

 CAObjHandle *workbookHandle)
{
 HRESULT __result = S_OK;
 CAObjHandle WorkbooksHandle = 0;
 CAObjHandle WorkbookHandleL = 0;

 if(!workbookHandle)
  __caErrChk (E_INVALIDARG);

 __caErrChk (Excel_GetProperty (applicationHandle,

ExcelRpt_GetErrorInfo(), Excel_AppWorkbooks,
  CAVT_OBJHANDLE, &WorkbooksHandle));

 __caErrChk (Excel_WorkbooksOpen (WorkbooksHandle,

ExcelRpt_GetErrorInfo(), fileName, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
         

CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
         

CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
         

CA_DEFAULT_VAL, CA_DEFAULT_VAL, &WorkbookHandleL));

Error:
    if(FAILED(__result))
        CA_DiscardObjHandle(WorkbookHandleL);
    else
        *workbookHandle=WorkbookHandleL;
    CA_DiscardObjHandle(WorkbooksHandle);
    return __result;
}

Veni Vidi Duci
0 Kudos
Message 6 of 6
(4,055 Views)