在unity根目录下创建Plugins文件夹,然后将两个动态链接库放进去。(Excel.dll和System.Data.dll)
链接:https://pan.baidu.com/s/1q1a3_poG1dZ3u1JveMaLUQ
提取码:7ob4
//直接调用load即可
public DataSet ReadExcel(string path)
{
FileStream stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read);
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
DataSet result = excelReader.AsDataSet();
excelReader.Close();
return result;
}
public void Load(string path)
{
DataSet resultds = ReadExcel(path);
int column = resultds.Tables[0].Columns.Count;
int row = resultds.Tables[0].Rows.Count;
Debug.Log("总行数:" + row + " 总列数:" + column);
//获得每行的名字,并添加到数组里
for (int i = 0; i < row; i++)
{
//answerList.Add(resultds.Tables[0].Rows[i][0].ToString());
//aList.Add(resultds.Tables[0].Rows[i][1].ToString());
//bList.Add(resultds.Tables[0].Rows[i][2].ToString());
//cList.Add(resultds.Tables[0].Rows[i][3].ToString());
//list.Add(resultds.Tables[0].Rows[i][4].ToString());
}
}