locked
Reading Excel Column Header using C# | Issue with formatting (?) RRS feed

  • Question

  • User-160758338 posted

    Hi Guys,

    I am having an excelsheet with around 10-15 columns. First three columns are having normal strings as header but rest are dates, formatted in "mmm-yy" format,like "Aug-10","Dec-10" etc.

    I am trying to read the excel using OleDBConnection like this:

    System.Data.OleDb.OleDbConnection MyConnection;
    
                    System.Data.OleDb.OleDbDataAdapter MyCommand;
                    MyConnection = new System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + filePath + "';Extended Properties=Excel 9.0;");
                    MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection);
                    MyCommand.TableMappings.Add("Table", "ExcelDataTable");
                    ds = new DataSet();
                    MyCommand.Fill(ds);
                    MyConnection.Close();

    The issue is, from the fourth column onwards, my dataset object does not show the exact column header, rather it shows F4,F5..etc as column header.

    Any help on how can I get the exact column headers (like Aug-10.Dec-10) ?
     

    Friday, July 16, 2010 5:33 AM

Answers

  • User-547121016 posted

    http://forums.asp.net/t/1581401.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, July 25, 2010 11:36 PM

All replies

  • User869274642 posted

    can you give me the example of the excel file? thanks

    Sunday, July 25, 2010 10:58 PM
  • User-547121016 posted

    http://forums.asp.net/t/1581401.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, July 25, 2010 11:36 PM