unity如何讀取Excel文件

unity如何讀取Excel文件

在使用unity開發過程中,許多時候需要策劃使用Excel去配表,如何再在unity引擎裡面讀取Excel,下面是代碼演示(注:需要引用Excel.dll):

private static void GetFaceInputPrioritys()

{

_faceInputPrioritys = new Dictionary();

FileStream stream = File.Open(Application.streamingAssetsPath + "/FaceInputPriority.xlsx", FileMode.Open, FileAccess.Read);

IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);

DataSet result = excelReader.AsDataSet();

DataTable table = result.Tables[0];

// int columns = table.Columns.Count;//列總數

int rows = table.Rows.Count;//行總數

string log = "";

for (int i = 1; i < rows; i++)

{

FaceInputPriority dto = new FaceInputPriority();

dto.Eyebrow = table.Rows[i][2].ToInt32();

dto.Eye = table.Rows[i][3].ToInt32();

dto.Pupil = table.Rows[i][4].ToInt32();

dto.Mouth = table.Rows[i][5].ToInt32();

dto.Cheek = table.Rows[i][6].ToInt32();

dto.Special = table.Rows[i][7].ToInt32();

dto.Misc = table.Rows[i][8].ToInt32();

_faceInputPrioritys[table.Rows[i][0].ToInt32()] = dto;

// log += dto.ID + " : " + dto.TypeName + "\n";

}

stream.Close();

// Debug.Log(log);

}


分享到:


相關文章: