string strConn = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + Server.MapPath("Book1.xls") + ";Extended Properties=Excel 8.0"; 
OleDbConnection conn = new OleDbConnection(strConn);
OleDbDataAdapter adp = new OleDbDataAdapter("Select * from [Sheet1$]",conn);
DataSet ds = new DataSet();
adp.Fill(ds,"Book1");我用上面的方法取得excel数据后 在table里显示 ,为什么显示不了excel里第一行的数据呀?
如果用datagrid就可以显示。
它好象是把excel里的第一行数据当做列头名,但为什么在table里显示不了呀,在datagrid就可以显示。 
该怎么解决呀 ? 谢谢了 。。

解决方案 »

  1.   

    我帮你们顶
    你们也去看看我的那个问题,有人说我的想法有问题,根本行不通,我同学说的
    http://community.csdn.net/Expert/topic/4892/4892388.xml?temp=.3035395
      

  2.   

    我也有过类似问题,但是只是出现在部分EXCEL文件中(不知道楼主是否也如此),我的解决方法有1.利用SQL导入到表看有没有问题
    2.检查格式是否特殊
    3.将表打开,将数据复制到自己新建的EXCEL中,怀疑有可能是EXCEL版本问题
    希望对你有帮助!!
      

  3.   

    设置HDR=YES 声明第1行是列头而非数据,否则设置成NO    *  Standard:
          "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyExcel.xls;Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"""          "HDR=Yes;" indicates that the first row contains columnnames, not data          "IMEX=1;" tells the driver to always read "intermixed" data columns as text. Note that this option might affect excel sheet write access negative.          TIP! SQL syntax: "SELECT * FROM [sheet1$]" - i.e. worksheet name followed by a "$" and wrapped in "[" "]" brackets.          TIP! Check out the [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Excel] located registry REG_DWORD "TypeGuessRows". That's the key to not letting Excel use only the first 8 rows to guess the columns data type. Set this value to 0 to scan all rows. This might hurt performance.          Important note! The two double quota ("") in the string are escaped quotas (VB syntax), you may have to change this to your language specific escape syntax (ex. \") or maybe single quota (').
      

  4.   

    to: fangxinggood
    我加了你说的 HDR=YES;IMEX=1后 
    它出错说 “ 找不到可安装的 ISAM。”
    不加就正确,只是就我所说的显示不了第一行数据。。
      

  5.   

    在table里显示?什么table?你使用怎么样的容器来显示数据可以肯定地是现在列头的信息都是DataTable里?那么列头应用 dt.Columns[i].ColumnName 来获取。