可以用npoi:
http://npoi.codeplex.com/
把npoi.dll放在unity里即可。
读取代码:
using System.IO;
using NPOI.SS.UserModel;
using NPOI.HSSF.UserModel;
using (FileStream stream = File.Open(m_excelPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
IWorkbook book = new HSSFWorkbook(stream);
for (int i = 0; i < book.NumberOfSheets; ++i) {
ISheet s = book.GetSheetAt (i);
Debug.Log ("sheetName:"+s.SheetName);
//s.LastRowNum的索引值,不是行总数,从0开始计数
for (int k = 0; k <= s.LastRowNum; ++k) {
IRow row = s.GetRow (k);
if (null == row) {
continue;
}
//print cell[0]
ICell cell = row.GetCell (0);
string cellValueStr= getCellValue (cell);
Debug.Log ("cellValueStr:"+cellValueStr);
}
}
}
protected string getCellValue(ICell cell)
{
if (null == cell) return "";
if (CellType.NUMERIC == cell.CellType) {
return cell.NumericCellValue.ToString ();
} else {
return cell.StringCellValue;
}
}