void LoadCodigosEspecie(string sFile) { int totalHojas, j, i; int ingresadas = 0, errores = 0; try { oBook = oExcel.Workbooks.Open(sFile);// .Workbooks.Open(sFile); totalHojas = oBook.Sheets.Count; D_Especie especie1 = new D_Especie(); E_Especie especie2; string texto; especie1.Conectar(); for (j = 1; j <= totalHojas; j++) { oSheet = (Microsoft.Office.Interop.Excel.Worksheet)oBook.Worksheets.get_Item(j);// .Worksheets(j);// oBook.Sheets(); i = 2; while (true) { texto = oSheet.Cells[i, 1].text; if (texto.Trim() == "") { break; } especie2 = new E_Especie(); especie2.Descripcion = oSheet.Cells[i, 1].text; if (especie1.Agregar(especie2)) { i++; ingresadas++; } else { Detalle += "Linea Excel " + i + ": " + especie1.Mensaje + "\n"; i++; errores++; } } // oSheet.Cells[1, 1] // oSheet.Activate() } if (ingresadas != 0 && errores != 0) { Mensaje = ingresadas + " entradas registradas con exito." + "\n" + errores + " entradas no se pudieron agregar."; } else { if (ingresadas == 0 && errores != 0) { Mensaje = ingresadas + " entradas no se pudieron agregar."; } else { if (ingresadas != 0 && errores == 0) { Mensaje = ingresadas + " entradas registradas con exito."; } else { Mensaje = "El archivo no tiene el formato correcto o no se han encontrado datos"; } } } } catch (Exception ex) { Mensaje = ex.Message; throw new Exception("Error Excel " + ex.Message); } }
public bool Agregar(E_Especie especie1) { D_Especie especie = new D_Especie(); return(especie.Agregar(especie1)); }