using UnityEngine;
using System.Collections;
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 struct DepenceTableData
{
public string word;
public string instruct;
}
public class ReadExcel : MonoBehaviour
{
public List<DepenceTableData> listdata;
void Start()
{
listdata = Load(Application.dataPath + "\\AppAsset\\" + "OutboundPedsData.xlsx");
foreach (var listing in listdata)
{
print(listing.instruct + " " + listing.word);
Debug.Log((listing.instruct + " " + listing.word + "\n").ToString());
}
}
public DataSet ReadExcelFun(string path)
{
FileStream stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read);
// CreateOpenXmlReader用于读取Excel2007版本及以上的文件
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
DataSet result = excelReader.AsDataSet();
excelReader.Close();
return result;
}
public List<DepenceTableData> Load(string path)
{
List<DepenceTableData> _data = new List<DepenceTableData>();
DataSet resultds = ReadExcelFun(path);
int column = resultds.Tables[0].Columns.Count;
int row = resultds.Tables[0].Rows.Count;
Debug.LogWarning(column + " " + row);
for (int i = 1; i < row; i++)
{
DepenceTableData temp_data;
temp_data.instruct = resultds.Tables[0].Rows[i][0].ToString();
temp_data.word = resultds.Tables[0].Rows[i][1].ToString();
Debug.Log(temp_data.instruct + " " + temp_data.word);
_data.Add(temp_data);
}
return _data;
}
}