var excelData = MiniExcel.Query(txtFileName.Text);
if (excelData.Count() <= 0)
{
MessageBox.Show("当前的Sheet页没有读取到对应的数据!");
}
else
{
DataRow dr = null;
int intI = 0;
foreach (IDictionary<string, object> row in excelData)
{
var rowsKeys = row.Keys.ToList();
var rowsValues = row.Values.ToList();
for (int i = 0; i < rowsKeys.Count; i++)
{
if (intI == 0)
{
dataGridTable.Columns.Add(rowsValues[i] == null ? "" : rowsValues[i].ToString(), typeof(string));
}
else
dr[i] = rowsValues[i];
}
if (intI > 0)
{
dataGridTable.Rows.Add(dr);
}
dr = dataGridTable.NewRow();
intI++;
}
dataGridInfo.DataSource = dataGridTable;
}