Autotests: how to catch, verify and close Excel window

Maria-SMaria-S Member Posts: 90
Dear Experts,

In my test codeunit I am running the report which produces and opens the excel worksheet.

I need to check the values in the produced excel and close the window.
Can anyone give me directions how to achieve this?

I guess it should be done using DotNet (in which I am not so experienced unfortunately).

What I've done:
I found the following piece of C# code:
instance = (Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
And I want to call same from NAV.

Now when I try to define the DotNet variable, I go to Assembly List, on the .NET tab I scroll to System.Runtime.InteropServices and select it. Now I expect that there will be list of Types, including Marshall, but the list is empty. Here I stuck.

Can anyone push me to the correct direction?


  • Options
    Jan_VeenendaalJan_Veenendaal Member Posts: 206
    You could look into the code that is in table 370 in NAV - there is a lot of code there to open/read/write Excel workbooks
    Jan Veenendaal
  • Options
    Maria-SMaria-S Member Posts: 90
    edited 2016-02-18
    Hi Jan,

    No-no, you see, I create AutoTest for the functionality that creates excel files (using table370 :)). So from test point of view I am running the report programmatically, and then I need to verify whether the report creates an excel file.

    My problem is that report generates the excel in temporary folder and opens it.
    Otherwise I would check that excel file exists in the folder.

    But now I need to check that opened excel file exists... and preferrably close it.

    Anyway, at this stage we decided to skip such export scenarios (we consider them untestable for now).
Sign In or Register to comment.