来源http://www.manew.com/thread-140829-1-1.html
第一步 创建文件夹
第二部导入
资源在此
链接:https://pan.baidu.com/s/1s1ZW-QU2XNik2ovPgbQr6Q
提取码:amcc
第三步 创建一个新场景将(下面)脚本挂在一个物体上面
using UnityEngine;
using UnityEngine.UI;
using Excel;
using System.Data;
using System.IO;
public class ReadExcel : MonoBehaviour
{
void Start()
{
Read();
}
private void Read()
{
string path = Application.streamingAssetsPath + "/XLSTest.xls";
FileStream stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read);
IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
//IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
DataSet result = excelReader.AsDataSet();
int rows = result.Tables[0].Rows.Count;
int cols = result.Tables[0].Columns.Count;
string text = "";
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
text += result.Tables[0].Rows[i][j].ToString() + "|";
}
text += "\n";
}
Debug.LogError(text);
}
}
如果这个不行
IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
就用这个
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);