using (var stream = System.IO.File.Open(textBox1.Text, FileMode.Open, FileAccess.Read))
{
using (IExcelDataReader reader = ExcelReaderFactory.CreateReader(stream))
{
DataSet ds = reader.AsDataSet(new ExcelDataSetConfiguration()
{
ConfigureDataTable = (_) => new ExcelDataTableConfiguration() { UseHeaderRow = true }
});
DataTableCollection tableCollection = ds.Tables;
if (tableCollection.Count > 0)
{
DataTable dt = tableCollection[0];
if(dt.Rows.Count > 0)
{
//
}
else
{
MessageBox.Show("Excel内容为空!");
}
}
}
}