免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
C#操作Excel(導(dǎo)入導(dǎo)出)
http://dev.csdn.net/article/72/72658.shtm

前些日子,有很多朋友說(shuō)需要C#導(dǎo)出到Excel的代碼,現(xiàn)共享給大家

/// <summary>
  /// 讀取Excel文檔
  /// </summary>
  /// <param name="Path">文件名稱</param>
  /// <returns>返回一個(gè)數(shù)據(jù)集</returns>
  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>
  /// 寫(xiě)入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 工號(hào)='日期'";
    //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$] (工號(hào),姓名,部門(mén),職務(wù),日期,時(shí)間) 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 ("寫(xiě)入Excel發(fā)生錯(cuò)誤:"+ex.Message );
   }
   return false;
  }

這種方法目前最有效,如果有不明白的地方可以來(lái)信交流

http://blog.csdn.net/flybird77/archive/2009/06/11/4258138.aspx

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
把Excel數(shù)據(jù)導(dǎo)入數(shù)據(jù)庫(kù)
導(dǎo)入excel錯(cuò)誤:外部表不是預(yù)期的格式 解決方案
用gridview顯示來(lái)自excel表格里的數(shù)據(jù)
ASP.net中讀取execl內(nèi)容
ASP.NET(C#) 讀取EXCEL ——另加解決日期問(wèn)題
C#操作Excel文件之OleDb
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服