Avatar of Michael Sterling
Michael Sterling
Flag for United States of America asked on

How do I get the following code to work for Excel 2010?

for some reason i couldn't get the code (included below) to work for Microsoft Excel 2010. I had to save the spread sheet into a 97 - 2003 format and then it worked. how do i get this to work for microsoft excel 2010, just incase. or for 2007 for that matter? the error i got was "file not in expected format" which is pretty self explanatory but i'd still like to get it to function for the later versions of excel if possible...
protected void UpLoadFile_Click(object sender, EventArgs e)
        System.Uri uri1 = new Uri(@"C:\src\StudyTimeTrackerPrimeI\Data\QUStudentInfo.xlsx");
        Uri relativeUri = uri1.MakeRelativeUri(uri1);
        OleDbConnection _con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source="+@"C:\src\StudyTimeTrackerPrimeI\Data\QUStudentInfo.xls;Extended Properties=Excel 12.0");

            System.Data.DataTable _tab = new System.Data.DataTable();
            System.Data.DataTable _SheetTable = new System.Data.DataTable();
            _SheetTable = _con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

            for (int Sheet = 0; Sheet < _SheetTable.Rows.Count; Sheet++)
                OleDbCommand _com = new OleDbCommand("SELECT * FROM [" + _SheetTable.Rows[Sheet][2].ToString() + "]", _con);
                OleDbDataAdapter _dap = new OleDbDataAdapter(_com);


                string _Meesage = string.Empty;
                for (int x = 0; x < _tab.Rows.Count; x++)
                    for (int y = 0; y < _tab.Columns.Count; y++)
                        _Meesage += _tab.Rows[x][y].ToString() + ",";

                    _Meesage += "\r\n";

                string _FileName = _SheetTable.Rows[Sheet][2].ToString();
                _FileName = _FileName.Replace("$", "");
                //_log.SuccessLoggingFileExcel(_FileName, _Meesage, Desitnation);
            // _log.SuccessLogging("UFL", "Mesage from the Success Logging From the user");  

            //return "Successessfully Parsed";

        catch (Exception ex)
            //Logging _lo = new Logging();
            //_log.LogErrorLog("Exception", ex);

Open in new window

C#ASP.NETMicrosoft Excel

Avatar of undefined
Last Comment
Michael Sterling

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Michael Sterling

i think you (disrupt) already helped me solve this in another thread...
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes