0

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

3
Contributors
8
Replies
9
Views
8 Years
Discussion Span
Last Post by emilio
0

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
                                                 );
            }

        }
0

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?

0

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

0

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

0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.