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

Recommended Answers

All 8 Replies

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

just to make sure, you have used the full path
C:\folder\Data.xls?

what version of excel?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.