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 SalmaTrader, 07-07-2026, 10:26 PM
    0 responses
    35 views
    0 likes
    Last Post SalmaTrader  
    Started by CarlTrading, 07-05-2026, 01:16 PM
    0 responses
    20 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 06-17-2026, 10:32 AM
    0 responses
    12 views
    0 likes
    Last Post CaptainJack  
    Started by kinfxhk, 06-17-2026, 04:15 AM
    0 responses
    18 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 06-17-2026, 04:06 AM
    0 responses
    20 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Working...
    X