using System.Collections;using System.Collections.Generic;using UnityEngine;using System.IO;using OfficeOpenXml;public class ExcelDemo : MonoBehaviour{ // Start is called before the first frame update void Start() { //CreateExcel(); ReadExcel(); }///创建 private void CreateExcel() { string createPath = Application.dataPath + "/Resources/Excel/test.xlsx"; FileInfo newFile = new FileInfo(createPath); if (newFile.Exists) { newFile.Delete(); newFile = new FileInfo(createPath); } using(ExcelPackage package=new ExcelPackage(newFile)) { ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("tableOne"); worksheet.Cells[1, 1].Value = "明晨"; worksheet.Cells["A2"].Value = "命辰"; package.Save(); } }///读取 private void ReadExcel() { Debug.Log("ReadExcel"); string readPath = Application.dataPath + "/Resources/Excel/test.xlsx"; FileInfo newFile = new FileInfo(readPath); if (!newFile.Exists) { Debug.Log("没有该文件" + newFile.FullName); return; } using (ExcelPackage package=new ExcelPackage(newFile)) { ExcelWorksheet worksheet = package.Workbook.Worksheets["tableOne"];//根据sheet获取Sheet int maxRow_Data = worksheet.Dimension.End.Row;//行 int maxColumn_Data = worksheet.Dimension.End.Column;//列 //按照索引字典,从数据Sheet中索取数据列 //实际数据从第二行开始 //List<content> contentList=GameFacade. for(int i = 1; i <= maxRow_Data; i++) { for(int j = 1; j <= maxColumn_Data; j++) { string data = System.Convert.ToString(worksheet.Cells[i, j].Value); Debug.Log("数据是" + data); } } } }}