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 cmoran13, 04-16-2026, 01:02 PM
    0 responses
    42 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    25 views
    0 likes
    Last Post PaulMohn  
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    162 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    98 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    157 views
    2 likes
    Last Post CaptainJack  
    Working...
    X