Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Read Excel File xlsx

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Read Excel File xlsx

    I was having a hard time read xlsx files in NT8, this worked for me.
    add a reference to C:\Windows\assembly\GAC\Microsoft.Office.Interop.E xcel\12.0.0.0__71e9bce111e9429c\Microsoft.Office.I nterop.Excel.dll

    you may need to install https://www.microsoft.com/en-us/down....aspx?id=13255 but i'm not sure

    Code:
                       string filePath2 = "file.xlsx";
                        Excel.Application xlApp = new Excel.Application();
                        Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(filePath2);
                        Excel._Worksheet xlWorksheet = (Excel._Worksheet)xlWorkbook.Sheets[1];
                        Excel.Range xlRange = xlWorksheet.UsedRange;
                        int rowCount = xlRange.Rows.Count;
                        int colCount = xlRange.Columns.Count;
                        Excel.Range startCell = (Excel.Range)xlWorksheet.Cells[1, 1];
                        Excel.Range endCell = (Excel.Range)xlWorksheet.Cells[rowCount, colCount];
                        Excel.Range range = xlWorksheet.Range[startCell, endCell];//worksheet.get_Range("A" + i.ToString(), "J" + i.ToString());
                        System.Array myvalues = (System.Array)range.Cells.Value;
                        for (int j = 1; j < rowCount; j++) 
                        {
    
                            for (int i = myvalues.GetLowerBound(0); i < myvalues.GetUpperBound(1); i++)
                            {
                                Print(myvalues.GetValue(j,i));
                            }
                        }
    
                        GC.Collect();
                        GC.WaitForPendingFinalizers();
                        //close and release
                        xlWorkbook.Close();
                        //quit and release
                        xlApp.Quit();

    #2
    Hello habibalex,

    This is outside of what our NinjaTrader Support is able to assist with.

    This thread will remain open for any community members that would like to assist.

    You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our business development follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request.


    Below I am including a link to another forum thread where using the excel dll is discussed.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    558 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    546 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X