How to Use Microsoft.Office.Interop.Excel on a MAChine Without Installed Ms Office

How to use Microsoft.Office.Interop.Excel on a machine without installed MS Office?

You can't use Microsoft.Office.Interop.Excel without having ms office installed.

Just search in google for some libraries, which allows to modify xls or xlsx:

  • http://code.google.com/p/excellibrary/
  • http://simpleooxml.codeplex.com/ (only xlsx)

Do i need to have office installed to use Microsoft.Office.Interop.Excel.dll

Yes, you are right. You need Excel to be installed to use the Excel Manipulation feature with Microsoft.Office.Interop.Excel.dll.


If you need to edit only .xlsx files, then you can use libraries like EPPlus. These libraries do NOT need Excel to be installed.

Using Office.Interop.Excel on machines where MS Office isn't installed

If you need to work only with open XML documents (*.xslx) you may consider using the Open XML SDK. See Welcome to the Open XML SDK 2.5 for Office for more information.

In case of binary file format you need to use any third-party components that don't required Office/Excel installed on the machine.

Pay special attention to the following fact:

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.

Using Microsoft.Office.Interop.Excel without actually having Excel?

You can install Microsoft Primary Interop Assemblies Package. You can find it here

But be careful. There are different packages for different office versions.

.NET core 3.0 and MS Office Interop

The solution to this is a bit quirky, but possible.

Create a new .NET Framework 4.X project. Add the relevant COM references to the project. Edit the .csproj of your .NET Core 3.0 project and add the generated references from the .NET Framework project to the <ItemGroup> tag.

It should look something similar to:

<ItemGroup>
<COMReference Include="Microsoft.Office.Core">
<Guid>{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}</Guid>
<VersionMajor>2</VersionMajor>
<VersionMinor>8</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>primary</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>

... more references

</ItemGroup>

Do not use the NuGet packages, they are not compatible with .NET Core.

Update:

You can now add the COM references straight from the IDE (since Visual Studio 2019 v16.6):

Sample Image



Related Topics



Leave a reply



Submit