Get only Excel column names in C#

Posted by Newbie on Stack Overflow See other posts from Stack Overflow or by Newbie
Published on 2010-05-05T06:47:01Z Indexed on 2010/05/05 6:48 UTC
Read the original article Hit count: 160

Filed under:

Is there any easy way apart from

ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+fileName+";Extended Properties='Excel 8.0;HDR=YES;IMEX=1'";
                using (objConn = new OleDbConnection(ConnectionString))
                {
                       objConn.Open();
                        Logger.Info("Reading the file "+fileName+"....");
                        objCmdSelect = new OleDbCommand("SELECT * FROM [" + sheetName + "$] WHERE 0 = 1", objConn);
                        objAdapter = new OleDbDataAdapter();
                        objAdapter.SelectCommand = objCmdSelect;
                        objDataset = new DataSet();
                        Logger.Info("Filling the dataset....");
                        objAdapter.Fill(objDataset, fileName);
                        Logger.Info("Returning the dataset....");
                        return objDataset;
                    }

and then looping the datatables for getting the excel column names given a filename and sheet name? Using C#(and no interop services)

Thanks

© Stack Overflow or respective owner

Related posts about c#3.0