Fail to load library at Excel.Workbooks.Open()

Using C# to write a custom node that writes date to specific cells on a Excel sheet. The code works fine as windows application. but got “Fail to load library” error while adding the dll into Dynamo. I’ve found the the first line that cause the error is at “excelApp.Workbooks.Open()”. Is there any steps that I missing in order to make this work? Thanks?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.DesignScript.Runtime;
using Autodesk.DesignScript.Interfaces;
using Microsoft.Office.Interop.Excel

public class Node
{
    public static void DynWriteToXl(double a, double b)
    {
        string fileName = "C:\\Schedule.xlsx";
            
        Microsoft.Office.Interop.Excel.Application excelApp;
        Microsoft.Office.Interop.Excel._Workbook wBook;
        Microsoft.Office.Interop.Excel._Worksheet wSheet;
        object misValue = System.Reflection.Missing.Value;

        excelApp = new Microsoft.Office.Interop.Excel.Application();
        //open
        wBook = excelApp.Workbooks.Open(fileName, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue);//This is the problem start
        wSheet = (Microsoft.Office.Interop.Excel.Worksheet)wBook.Worksheets.get_Item(1);

        ////write
        double col = 2;
        wSheet.Cells[6, col] = a;
        wSheet.Cells[7, col] = b;

        try
        {
        //save
        excelApp.DisplayAlerts = false;
        wBook.SaveAs(fileName, misValue, misValue, misValue, misValue, misValue, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, misValue, misValue, misValue, misValue, misValue);
        wBook.Close(true, fileName, misValue);// close the worksheet
        }
        finally
        {
            if (excelApp != null)
            {
                excelApp.Quit(); // close the excel application
            }
        }
    }

}

any one? Please…:disappointed:

Hi @glenncai

Did you try @Konrad_K_Sobon 's nodes from archi-lab package?

What does the error says?

Did you check if there is no suitable solution mentioned in this thread?

@glenncai do you have excel installed?

Hi Kulkul
There is no error while compile my code in Visual Studio.
This is the one of line I believe that cause “Fail to load library” message in Dynamo, because if I stop compile my code before the line: excelApp.Workbooks.Open() the dll will load successfully.

Hi John
Yes I do, Excel 2013

Hi, I’m facing similar issue, have you found solution?