捣鼓了半天才弄出来,网是的资料层次不齐记录整理一下少走弯路。参考地址:Unity3D研究院之MAC&Windows跨平台解析Excel(六十五);
1.下载三个所需动态链接库,链接:https://pan.baidu.com/s/1vSR6b334YdH8RfLqtJDoRw
提取码:8duf
复制这段内容后打开百度网盘手机App,操作更方便哦
2.将下载下来的文件解压,将三个dll放到unity的Plugins文件夹下(没有创建,如图):
3.下面是测试代码(代码来自上面参考博文):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using Excel;
using System.Data;
public class NewBehaviourScript : MonoBehaviour
{
void Start ()
{
XLSX();
}
void XLSX()
{
FileStream stream = File.Open(Application.dataPath + "/UserLevel1.xlsx", FileMode.Open, FileAccess.Read);
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
do{
// sheet name
Debug.Log(excelReader.Name);
while (excelReader.Read()) {
for (int i = 0; i < excelReader.FieldCount; i++) {
string value = excelReader.IsDBNull(i) ? "" : excelReader.GetString(i);
Debug.Log(value);
}
}
}while(excelReader.NextResult());
}
}
反正东西都是别人的,如果偷了谁的劳动成果没注明的,在下愿意被暴揍一顿。