首先导入必要的dll文件
然后就可以引用命名空间using OfficeOpenXml;
void Start ()
{
string path = Application.dataPath + “/new.xls”;
FileInfo fileinfo = new FileInfo(path);
Debug.Log(Application.dataPath);
Debug.Log(fileinfo.Exists);
ExcelPackage ep = new ExcelPackage(fileinfo);
ExcelWorksheet excelworksheet = ep.Workbook.Worksheets[1];//获取excel的第几张表格 例如:如果sheet1 则索引值为1 记住是1 不是0开始
for (int i = 1; i <= excelworksheet.Dimension.End.Row; i++) //遍历
{
string a = excelworksheet.Cells[i, 1].Value.ToString();//cells[]取值
string b = excelworksheet.Cells[i, 2].Value.ToString();
string c = excelworksheet.Cells[i, 3].Value.ToString();
Debug.Log(a + " " + b + " " + c + “\n”);
}
// Debug.Log(excelworksheet.Cells[1, 1].Value.ToString());
}
备注:excel 尽量使用 office 的excel 不要使用wps 格式可以是xls 或者xlsx