csharp leer excel
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp leer excel相关的知识,希望对你有一定的参考价值。
using (OleDbConnection conn = new OleDbConnection())
{
string fileNameWithPath = @ConfigurationManager.AppSettings["ExcelSIP"].ToString();
DataTable dt = new DataTable();
string fileExtension = Path.GetExtension(fileNameWithPath);
if (fileExtension == ".xls" | fileExtension == ".XLS")
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileNameWithPath + ";" + "Extended Properties='Excel 8.0;HDR=YES;'";
if (fileExtension == ".xlsx" | fileExtension == ".XLSX")
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileNameWithPath + ";" + "Extended Properties='Excel 12.0 Xml;HDR=YES;'";
using (OleDbCommand comm = new OleDbCommand())
{
comm.CommandText = "Select * from [Hoja1$]";
comm.Connection = conn;
using (OleDbDataAdapter da = new OleDbDataAdapter())
{
da.SelectCommand = comm;
da.Fill(dt);
foreach (DataRow row in dt.Rows)
{
string oficina = row[6].ToString();
if (!listaOficinasEnviadas.Contains(oficina))
{
crearExcel(oficina);
mandarCorreo(oficina);
listaOficinasEnviadas.Add(oficina);
}
}
}
}
}
以上是关于csharp leer excel的主要内容,如果未能解决你的问题,请参考以下文章
csharp Leer XML
java capturar recibir leer listview
java leer recuperar valor textbox
css Leere Elemente verstecken
xml leer xml con jQuery
Leer parÓ地铁”