0

We have an excel macro which reads the spreadsheet content's (no write access).

We need to migrate the code to run it headless server side.

To minimize migration effort we think of rewriting the macro in VB.NET by using Microsoft Interop.

Here it is proposed to create a VB.NET executable which uses Office Interop without having excel installed.

Question: is it really possible to do so? Can I execute VB.NET using Office Interop to read a spreadsheet whithout having excel installed?

Abid
  • 565
  • 1
  • 5
  • 15
  • 1
    There are suggestions in this [comment by Caius Jard](https://stackoverflow.com/questions/68619054/how-to-shut-down-excel-for-good-in-vb-net#comment121269898_68619054). – Andrew Morton Aug 02 '21 at 14:28
  • @AndrewMorton Thank you. But I am just interested if there's a way to run Office interop without an excel installation even if only read access is needed. – Abid Aug 02 '21 at 14:34
  • 1
    There is no way to use interop assemblies without MS Office installed (applications where interops come from). – Eugene Astafiev Aug 03 '21 at 08:06

2 Answers2

0

Here is what MS states for the server-side automation:

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.

Read more about that in the Considerations for server-side Automation of Office article.

As possible alternatives you may consider using the Open XML SDK if you deal with open XML documents only. Otherwise, you may consider using third-party libraries that don't require Office installed.

There is no way to use interop assemblies without MS Office installed (applications where interops come from).

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • So I guess this comment https://stackoverflow.com/questions/5845770/using-microsoft-office-interop-excel-without-actually-having-excel?rq=1#comment15952138_6135141 is wrong .... – Abid Aug 02 '21 at 14:42
  • The quote from Microsoft concerns installations of Office. The OP wants to avoid installing Office, thus the notice about installations of Office not being supported does not apply. – GSerg Aug 02 '21 at 14:45
  • It is up to you which component is to use. If NPOI doesn't require Office applications installed on the server - that is a way to go definitely. – Eugene Astafiev Aug 02 '21 at 14:45
  • Actually all I want to know if my original question can be answered with yes or no .. – Abid Aug 03 '21 at 07:37
0

As written in the comments and in many other sources, it's not possible to use MS Interop Assemblies without having MS Office installed.

The proposal which I mentioned in the original question seems to be wrong.

Abid
  • 565
  • 1
  • 5
  • 15