# C# help - How to read excel

**URL:** <https://forum.dynamobim.com/t/c-help-how-to-read-excel/93703>\
**Category:** Developers\
**Tags:** revit, excel\
**Created:** [September 12, 2023, 1:16pm UTC](https://forum.dynamobim.com/t/c-help-how-to-read-excel/93703 "2023-09-12T13:16:26Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![RMohareb](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/rmohareb/32/120534_2.png) [@RMohareb](https://forum.dynamobim.com/u/RMohareb)\
**Post date:** [September 13, 2023, 6:47am UTC](https://forum.dynamobim.com/t/c-help-how-to-read-excel/93703/5 "2023-09-13T06:47:32Z")

</div>

Hi @Alien  
To accsess Excel in Dynamo, you need use late binding to access the Excel API. This is because Dynamo is already accessing the Excel API. Challenges may arise when trying to access the API of another package, especially if Dynamo has already established a connection to it. This issue was solve by @zachri.jensen.

> [@Fail to Load two packages access to the same API](https://forum.dynamobim.com/t/fail-to-load-two-packages-access-to-the-same-api/83556):
>
> Dynamo can not load two packages access to the same API.for Example I can not use Civilconnection package and BriMohareb\_23 at the same time. I need to remove one of them and use only one becuse both access to civil 3d api. Is any way to load both togethe?. here the error if i try to load BriMohareb\_23 when i already load civilconnection [image]

The below code to accses Excel by using late binding

```auto
    public static string Set_Value_at_Range(string workbookPath,string sheetName, string Range, string Value,bool Visible, bool save,bool Close)
        {

          
                try
            {

          
                        
            // Specify the file path and name of the Excel file
            string filePath = workbookPath;

            // Use late binding to create an instance of the Excel application
            Type excelType = Type.GetTypeFromProgID("Excel.Application");
            object excel = Activator.CreateInstance(excelType);

            // Use late binding to open the Excel file
            object workbooks = excelType.InvokeMember("Workbooks", BindingFlags.GetProperty, null, excel, null);
            object workbook = workbooks.GetType().InvokeMember("Open", BindingFlags.InvokeMethod, null, workbooks, new object[] { filePath });

            // Use late binding to access the first worksheet
            object sheets = workbook.GetType().InvokeMember("Sheets", BindingFlags.GetProperty, null, workbook, null);

            object sheet = sheets.GetType().InvokeMember("Item", BindingFlags.GetProperty, null, sheets, new object[] { sheetName });
            if (Visible)
            {
                excelType.InvokeMember("Visible", BindingFlags.SetProperty, null, excel, new object[] { true });
            }
        
            // Use late binding to add a value to cell "C3"
            object range = sheet.GetType().InvokeMember("Range", BindingFlags.GetProperty, null, sheet, new object[] { Range });
            range.GetType().InvokeMember("Value", BindingFlags.SetProperty, null, range, new object[] { Value });
             if (save)
                {
                    // Use late binding to save the changes to the Excel file
                workbook.GetType().InvokeMember("Save", BindingFlags.InvokeMethod, null, workbook, null);                       
            }
       
            if (Close)
            {
                    // Use late binding to close the Excel file and quit the application
                    workbook.GetType().InvokeMember("Close", BindingFlags.InvokeMethod, null, workbook, null);
                    excelType.InvokeMember("Quit", BindingFlags.InvokeMethod, null, excel, null);
            }

                return "Done";
            }
            catch (Exception)
            {

                return "fail";

            }

            }
        

        }

```

i use it in my pak. BriMohareb\_XX to accsess excel and create some node like Run Macro from dynamo.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/0/60edcb9f1420a9b1accf24fca93b7aa54d72b383.png)

> [@"BriMohareb\_XXXX" Package for RevitXXXX Thread](https://forum.dynamobim.com/t/brimohareb-xxxx-package-for-revitxxxx-thread/84362/4):
>
> New release (V 5.0.0), 1- New Nodes are added to handle Excel Not: I use ChatGPT disguised_face disguised_face disguised_face disguised_face to write C# code for the below node (excel nodes) upside_down_face upside_down_face upside_down_face upside_down_face ChatGPT 2- fix extract Reference from element Now you can use this node to add Dimention 3- Send a Command to multi cad file

---

_[View the full topic](https://forum.dynamobim.com/t/c-help-how-to-read-excel/93703)._
