hello
is there a way i can read from a table in microsoft exel file into an array or matrix in c# ?

i tried to use this code and on line 15 i get null pointer error.
i dont know the reason.
the workBookToOpen string i wrote is in my projects directory

private void Form1_Load(object sender, EventArgs e)
        {
            OpenWorkBook("Data.xls");
        }

        public static void OpenExcelApplication()
        {
            ExlApp = new ExcelXptlb.Application();
        }

        public static void OpenWorkBook(string WorkBookToOpen)
        {
            if (WorkBookToOpen != null)
            {
                ExlWrkBook = ExlApp.Workbooks.Open(WorkBookToOpen.ToString()
                                                    , Opt
                                                    , Opt
                                                    , Opt
                                                    , Opt
                                                    , Opt
                                                    , Opt
                                                    , Opt
                                                    , Opt
                                                    , Opt
                                                    , Opt
                                                    , Opt
                                                    , Opt
                                                    , Opt
                                                    , Opt
                                                 );
            }

        }

for one, you don't need to call WorkBookToOpen.ToString(), it already is a string

is workbooktoopen a valid path? and are you calling open first?

i deleted the ToString
the excel file is in my projects folder
i tried it like this too OpenWorkBook("..\\..\\Data.xls");

it gives the same null pointer error

i tried like this OpenWorkBook("C:\\Data.xls");
it's excel from office 2003

i checked again and as you said i forgot to open excel applicaton.
i tried it with ("c:\\data.xls") and it worked.
thanks for the help

This question has already been answered. Start a new discussion instead.