rt
提供资料链接也可以用OleDb

解决方案 »

  1.   

    public DataSet ExcelToDS(string Path)
      {
       string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +"Data Source="+ Path +";"+"Extended Properties=Excel 8.0;";
       OleDbConnection conn = new OleDbConnection(strConn);
       conn.Open();  
       string strExcel = "";   
       OleDbDataAdapter myCommand = null;
       DataSet ds = null;
       strExcel="select * from [sheet1$]";
       myCommand = new OleDbDataAdapter(strExcel, strConn);
       ds = new DataSet();
       myCommand.Fill(ds,"table1");   
       return ds;
      }
    /// <summary>
      /// 写入Excel文档
      /// </summary>
      /// <param name="Path">文件名称</param>
      public bool SaveFP2toExcel(string Path)
      {
       try
       {
        string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +"Data Source="+ Path +";"+"Extended Properties=Excel 8.0;";
        OleDbConnection conn = new OleDbConnection(strConn);
        conn.Open();  
        System.Data.OleDb.OleDbCommand cmd=new OleDbCommand ();
        cmd.Connection =conn;
        //cmd.CommandText ="UPDATE [sheet1$] SET 姓名='2005-01-01' WHERE 工号='日期'";
        //cmd.ExecuteNonQuery ();
        for(int i=0;i<fp2.Sheets [0].RowCount -1;i++)
        {
         if(fp2.Sheets [0].Cells[i,0].Text!="")
         {
          cmd.CommandText ="INSERT INTO [sheet1$] (工号,姓名,部门,职务,日期,时间) VALUES('"+fp2.Sheets [0].Cells[i,0].Text+ "','"+
           fp2.Sheets [0].Cells[i,1].Text+"','"+fp2.Sheets [0].Cells[i,2].Text+"','"+fp2.Sheets [0].Cells[i,3].Text+
           "','"+fp2.Sheets [0].Cells[i,4].Text+"','"+fp2.Sheets [0].Cells[i,5].Text+"')";
          cmd.ExecuteNonQuery ();
         }
        }
        conn.Close ();
        return true;
       }
       catch(System.Data.OleDb.OleDbException ex)
       {
        System.Diagnostics.Debug.WriteLine ("写入Excel发生错误:"+ex.Message );
       }
       return false;
      }请看:
    http://community.csdn.net/Expert/topic/4125/4125390.xml?temp=.5928156
      

  2.   

    http://dev.csdn.net/develop/article/73/73912.shtm
      

  3.   

    有两种方法,使用数据库方式,mapserver(杨东)给出的示例,另一种方法使用COM方式
      

  4.   

    http://community.csdn.net/Expert/topicview.asp?id=4176683
      

  5.   

    http://www.spicy-girl.net/forum/other/200581/070a3579f424988a.asp
      

  6.   

    错了,是http://www.cnblogs.com/lingyun_k/archive/2005/07/12/191740.html
      

  7.   

    我是判断进程启动时间来结束Excel进程
      

  8.   

    你可到如下地址看一个类
    http://www.journeychina.com/OfficeEditor/
      

  9.   

    微软官方网站有一篇KB文章专门陈述了如何在ASP.NET中使用OleDB来访问和读取Excel文件中的数据,只需要对应的SQL语句更改即可:
    http://support.microsoft.com/default.aspx?scid=kb;zh-cn;306572