今天想弄个Unity读取Excel的功能的,发现网上有许多方法,采用其中一种方法:加入库文件 Excel.dll 和ICSharpCode.SharpZipLib.dll库文件,(还有System.Data.dll也要拷贝进来,在Unity安装路径C:\Program Files\Unity\Editor\Data\Mono\lib\mono\unity中),代码下载链接在最后。
使用时要注意1997-2003和2007版本的脚本不一样:
然后编写脚本DoExcel.cs:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Data;
using System.IO;
using Excel;
public class DoExcel {
public static DataSet ReadExcel(string path)
{
FileStream stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read);
// CreateOpenXmlReader用于读取Excel2007版本及以上的文件
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
DataSet resu