怎么读取呢?
最好能指定单元格读取

解决方案 »

  1.   

    System.Xml.Xsl.XslTransform.Load(String)
      

  2.   

    private void importbutton_Click(object sender, System.EventArgs e)
    {
    ConStr=ConfigurationSettings.AppSettings["ConStr"];
    Conn=new SqlConnection(ConStr); string fileName=Server.MapPath("")+"\\upload"+"\\test.xls";
    myFile.PostedFile.SaveAs(fileName);
    string extName=System.IO.Path.GetExtension(myFile.PostedFile.FileName);
    if(extName!=".xls"||extName.Length<1)
    {
    Response.Write( "<script language=javascript>alert('数据导入失败.可能是文件格式或路径不正确!!!');</script>");
    return;
    } string mystring="Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = '"+fileName+"'"+";Extended Properties=Excel 8.0";
    OleDbConnection cnnxls = new OleDbConnection (mystring);
    OleDbDataAdapter myDa =new OleDbDataAdapter("select * from [Sheet1$]",cnnxls);
    DataSet myDs =new DataSet();
    myDa.Fill(myDs,"DWJBQK");
    if(myDs.Tables[0].Rows.Count<=0)
    {
    Response.Write( "<script language=javascript>alert('文件中可能没有数据,请检查后重新导入!');</script>");
    return;
    } dwid=new int[myDs.Tables[0].Rows.Count];
    string strSql = "";
    string CnnString="Provider=SQLOLEDB;"+ConStr;
    OleDbConnection conn =new OleDbConnection(CnnString);
    OleDbCommand myCmd =null; try
    {
    conn.Open ();
    for(int i=0; i<myDs.Tables[0].Rows.Count; i++)
    {
    strSql="insert into DWJBQK(DWMC,ZGBM,GDZCZE,FRDB,DWWZ,EMAIL,LXR,LXDH,DWGK) values ('";
    strSql += myDs.Tables[0].Rows[i]["DWMC"].ToString() + "', '";
    strSql += myDs.Tables[0].Rows[i]["ZGBM"].ToString() + "', "; strSql += myDs.Tables[0].Rows[i]["GDZCZE"].ToString() +", '";
    strSql += myDs.Tables[0].Rows[i]["FRDB"].ToString() + "', '";
    strSql += myDs.Tables[0].Rows[i]["DWWZ"].ToString() + "', '";
    strSql += myDs.Tables[0].Rows[i]["EMAIL"].ToString() +"', '"; strSql += myDs.Tables[0].Rows[i]["LXR"].ToString() + "', '";
    strSql += myDs.Tables[0].Rows[i]["LXDH"].ToString() + "', '";
    strSql += myDs.Tables[0].Rows[i]["DWGK"].ToString()  + "')"; strSql +="select @@IDENTITY"; try
    {
    myCmd=new OleDbCommand(strSql,conn);
    dwid[i]=int.Parse(myCmd.ExecuteScalar().ToString().Trim());
    }
    catch
    {
    Response.Write( "<script language=javascript>alert('数据导入失败!');</script>");
    return;
    }
    }
    }
    catch
    {
    Response.Write( "<script language=javascript>alert('数据导入失败!');</script>");
    return;
    }
    finally
    {
    conn.Close();

    }
    Response.Write("<script language=javascript>alert('操作成功.共导入"+myDs.Tables[0].Rows.Count+"条记录!');window.location.href='cddw_excel.aspx?total="+myDs.Tables[0].Rows.Count+"';</script>");
    }
      

  3.   

    是xls不是xsl
    我在winform里面做得- -
      

  4.   

    就是读excel文件,搜一下先,应该比较多的帖子讨论这个问题的。
      

  5.   

    http://blog.csdn.net/fangxinggood/archive/2006/04/08/655313.aspx
      

  6.   

    这是一个简单读取EXCEL文件到DATAGRID中的小例子:
    string mystring="Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source ='e:\\20051215销售发票.zzp' ; Extended Properties=Excel 8.0";
    OleDbConnection conn = new   OleDbConnection (mystring);
    conn.Open();
    OleDbDataAdapter myDa =new OleDbDataAdapter("select * from [Sheet1$]",conn);
    DataSet myDs =new DataSet();
    myDa.Fill(myDs,"xls");

    this.dataGrid1.DataSource=myDs.DefaultViewManager;
    conn.Close();
      

  7.   

    Excel.ApplicationClass   excel   =   new   ApplicationClass();   
      excel.Application.Workbooks.Add(true);   
      excel.Visible   =   false;   
      string   ExcelFile   ="D:\\111.xls";   
      object   missing   =   System.Reflection.Missing.Value;   
      excel.Workbooks.Open(ExcelFile,   missing,   missing,   missing,   missing,   missing,   missing,   missing,   
      missing,   missing,   missing,   missing,   missing);   
        
      this.textBox1.Text   =   ((System.Object)(((Excel.Range)(((Excel.Range)(excel.ActiveCell)).Cells)).FormulaR1C1Local)).ToString();   
        
        
      //FormulaR1C1Local   
      //row1col1得值   
      

  8.   

    GemBox ExcelLite Free 2.3 free edtion 
    download from www.dnc.com.cn