Can we use Microsoft.Office.Interop.excel.dll in Azure funtions?

I want to export data from data table to Excel using Microsoft.Office.Interop.excel.dll in azure functions. I have added the dll in wwwroot inside the azure functions as well I've added the project.json with the dll depencies. Here is my issue.

ERROR: Exception while executing function: Functions.TimerTriggerCSharp1. Microsoft.Azure.WebJobs.Script: One or more errors occurred. f-TimerTriggerCSharp1__-1571765013: Could not load file or assembly 'office, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified.

Used: #r "Microsoft.Office.Interop.Excel.dll"

My project.json file:

{
  "frameworks": {
    "net46": {
      "dependencies": {
        "Microsoft.Office.Interop.Excel": "14.0.0.0"
      }
    }
  }
}

Upvotes: 0

Views: 3522

Answers (1)

Murray Foxcroft
Murray Foxcroft

Reputation: 13765

Microsoft.Office.Interop.Excel.dll has many dependencies. It relies on having the relevant Microsoft Office product installed (or a subset thereof) on the target machine. I think with enough effort and fiddling you may get this to work, and even then I am not sure how reliable it will be. These Interop assemblies are typically used for client side interactions with Microsoft Office (i.e. for thick client desktop applications) and is not the correct approach for building server/service code for interacting with documents.

Microsoft's Open XML SDK is free to use and provides libraries for interacting with Microsoft Office documents (including Excel of course). Switch your code over to using this library, unfortunately you will have a bit of rework to do, but you will have the right architecture/components for dealing with server side programming against Office documents. Alternatively there are paid for options, see possible nuget packages here. Keep in mind that you want a library that is geared more for server side than client side execution.

Upvotes: 2

Related Questions