Excel Interop RunOnClient=No

mrQQmrQQ Member Posts: 239
edited 2014-09-29 in NAV Three Tier
Hello,

I have a requirement to import excel file using NAS.

I have following code:
XlApplicationServer := XlApplicationServer.ApplicationClass;

XlHelperServer.CallOpen(XlApplicationServer,'C:\TEMP\file.xlsx');

XlApplicationServer.Visible := TRUE;

XlWorkBookServer := XlApplicationServer.ActiveWorkbook;
XlWorkSheetsServer := XlWorkBookServer.Worksheets;
MESSAGE(FORMAT(XlWorkSheetsServer.Count));

It works absolutely fine if I set RunOnClient=Yes for all the .NET variables.

However, if I set it to No, I get following error on the MESSAGE line:
Microsoft Dynamics NAV
---------------------------

A call to System.__ComObject.Count failed with this message: Object does not match target type.
---------------------------
OK
---------------------------

The service is running on my own PC, started with my own username.

What is the problem here?

Comments

  • VjekoVjeko Member Posts: 55
    I believe there is no solution to this, and what you are trying to do is not possible the way you are trying to do it.

    Now, I am not 100% sure about this, but I think it absolutely has to do with support for 32-bit COM under 64-bit environment.

    The problem is, the .NET Excel interoperability is not .NET at all, it's merely a .NET wrapper around COM objects that uses COM Interop inside .NET to actually communicate with Excel. Since COM (Automation) is only supported client-side, anything that you attempt to do with it on the server side may not work properly. Obviously, you've found one instance of this.

    I am not quite sure if it is related to this problem, but take a look at this:
    http://stackoverflow.com/questions/8263 ... -on-64-bit

    Also, consider opening Excel files through ADO.NET. I have some examples here:
    http://vjeko.com/blog/excel-interoperab ... n-nav-2013

    Good luck!
    (Co-)author of "Implementing Microsoft Dynamics NAV 2009"
    http://vjeko.com/
Sign In or Register to comment.