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 CaptainJack, 05-29-2026, 05:09 AM
    0 responses
    232 views
    0 likes
    Last Post CaptainJack  
    Started by CaptainJack, 05-29-2026, 12:02 AM
    0 responses
    150 views
    0 likes
    Last Post CaptainJack  
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    161 views
    1 like
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    243 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    198 views
    0 likes
    Last Post CarlTrading  
    Working...
    X