c# 가져온 excel 파일 읽기, 대량 처리 데이터 순환

3565 단어
    
dt = FM_HR_ShiftMaintenanceManager.GetCsvToDataTable(strConn, excelName,"XJSQMonthlyImportExcelData"); int iCount = dt.Rows.Count; StringBuilder sb = new StringBuilder(); if (dt != null) { int loop = Convert.ToInt32(Math.Floor((iCount / 100) * 1.0)); DlSoft.Liveflow.Common.Log.LogHelper.Logger.Write("loop :"+loop); if (loop < 1) { for (int j = 0; j < iCount; j++) { if (!string.IsNullOrEmpty(dt.Rows[j][1].ToString())) { sb.Append(dt.Rows[j][0].ToString() + "@@" + dt.Rows[j][1].ToString() + "$$"); } } ssql = string.Format(@"exec usp_UpdateXiuJiaSQMonthlyStatus '{0}'", sb.ToString()); int t = dbt.ExecuteNonQuery(ssql); } else { for (int k = 0; k < loop; k++) { for (int l = 0; l < 100; l++) { if (!string.IsNullOrEmpty(dt.Rows[l + k * 100][1].ToString())) { sb.Append(dt.Rows[l + k * 100][0].ToString() + "@@" + dt.Rows[l + k * 100][1].ToString() + "$$"); } } if (!string.IsNullOrEmpty(sb.ToString())) { ssql = string.Format(@"exec usp_UpdateXiuJiaSQMonthlyStatus '{0}'", sb.ToString()); int tt = dbt.ExecuteNonQuery(ssql); sb.Remove(0, sb.Length); } } for (int m = 0; m < iCount - loop * 100; m++) { if (!string.IsNullOrEmpty(dt.Rows[m + loop * 100][1].ToString())) { sb.Append(dt.Rows[m + loop * 100][0].ToString() + "@@" + dt.Rows[m + loop * 100][1].ToString() + "$$"); } } if (!string.IsNullOrEmpty(sb.ToString())) { ssql = string.Format(@"exec usp_UpdateXiuJiaSQMonthlyStatus '{0}'", sb.ToString()); int ttt = dbt.ExecuteNonQuery(ssql); } } }

  
excel 데이터 가져오기
   /// 
        ///  excel .xlsxs
        /// 
        ///  
        /// exec 
        /// excel 
        /// exce 
        /// 
        public static DataTable GetCsvToDataTable(string strConn, string excelName, string FillName)
        {
            OleDbConnection conn = new OleDbConnection(strConn);
            conn.Open();
            DataSet ds = new DataSet();
            OleDbDataAdapter odda = new OleDbDataAdapter(string.Format("select * from [" + excelName + "$]"), conn);  // ,  CSV 
            odda.Fill(ds, FillName);
            conn.Close();
            return ds.Tables[0];
        }

  
다음으로 전송:https://www.cnblogs.com/yachao1120/p/9497954.html

좋은 웹페이지 즐겨찾기