Cómo usar la programación C# para leer datos en Excel en un bucle
DataTable privado ExcelImport(string excelpath)
{
string path = excelpath;
string strConn = "Provider=Microsoft.Jet .OLEDB.4.0; Fuente de datos="ruta"; Propiedades extendidas='Excel 8.0; HDR=NO;'";
OleDbConnection conn = new OleDbConnection( strConn);
conn.Open();
System.Data.DataTable esquemaTable = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null);
cadena tableName = esquemaTable.Rows[0][2].ToString().Data.DataTable tempDt = nuevo System.Data.DataTable();
//System.Data.DataSet excelDt = nuevo System.Data.DataSet ();
OleDbDataAdapter da = new OleDbDataAdapter(strExcel, conn);
da.Fill(tempDt);
conn.Close(); p>
p>
excelDt = tempDt.Clone();
for (int i = 0; i lt; tempDt.Rows.Count; i )
{
cadena cellstr = tempDt.Rows[i][0].ToString();
if (cellstr.Length == 0)
continuar;
bool digitsOnlyck = getDigitsOnly(cellstr);
if (!digitsOnlyck)
Continuar;
excelDt.ImportRow( tempDt.Rows [i]);
}
tempDt.Dispose();
Devuelve excelDt;