/// <summary> /// 根据表名获取到表数据存放到TableDatas类中 /// </summary> /// <param name="tableName">表名</param> /// <returns></returns> public TableDatas FindExcelFiles(string tableName) { string filePath = Application.streamingAssetsPath + "\\TableFiles\\111.xlsx"; //StreamingAssets文件夹的相对路径 FileInfo fileinfo = new FileInfo(filePath); //Debug.Log("打开文件路径:"+fileinfo); ExcelPackage excelPackage = new ExcelPackage(fileinfo); TableDatas tableData = new TableDatas(); tableData.worksheet = excelPackage.Workbook.Worksheets[tableName]; if (tableData.worksheet == null || excelPackage == null) { Debug.Log(tableName + "表数据或许为null"); return(null); } else { Debug.Log("获取 " + tableName + " 表数据 " + excelPackage); int num = 1; //计算表的总行数和列数 while (tableData.worksheet.Cells[num++, 1].Value != null) { } tableData.rows = num - 2; num = 1; while (tableData.worksheet.Cells[1, num++].Value != null) { } tableData.columns = num - 2; return(tableData); } }
/// <summary> /// 获取到相应行的所有数据 /// </summary> /// <param name="tabledata"></param> /// <param name="row"></param> /// <returns></returns> public List <string> GetRowDatas(TableDatas tabledata, int row) { List <string> datas = new List <string>(); int i = 1; while (i <= tabledata.columns) { datas.Add((tabledata.worksheet.Cells[row, i].Value != null) ? tabledata.worksheet.Cells[row, i].Value.ToString() : ""); i++; } return(datas); }
/// <summary> /// 获取到相应列的所有数据 /// </summary> /// <param name="tabledata"></param> /// <param name="column"></param> /// <returns></returns> public List <string> GetColumnDatas(TableDatas tabledata, int column) { List <string> datas = new List <string>(); int i = 1; while (i <= tabledata.rows) { datas.Add((tabledata.worksheet.Cells[i, column].Value != null) ? tabledata.worksheet.Cells[i, column].Value.ToString() : ""); i++; } return(datas); }
/// <summary> /// 根据行列值获取表数据类中的某个数据 /// </summary> /// <param name="tabledata"></param> /// <param name="row"></param> /// <param name="column"></param> /// <returns></returns> public string GetRowAndColumnData(TableDatas tabledata, int row, int column) { if (row > tabledata.rows || column > tabledata.columns) { Debug.Log("索引超出表格范围!"); return(null); } else { if (tabledata.worksheet.Cells[row, column].Value == null) { Debug.Log("该表格数据为空"); return(""); } else { return(tabledata.worksheet.Cells[row, column].Value.ToString()); } } }
TableDatas worksheet_Role; //存储武将表 private void Awake() { //worksheet_NPC = useepplusfun.FindExcelFiles("NPCTable"); //获取NPC数据表 worksheet_Role = useepplusfun.FindExcelFiles("RoleTable1"); //武将表数据 battles = 1; }
private void Awake() { worksheet_Role_EmFight = useepplusfun.FindExcelFiles("RoleTable1"); worksheet_DFC = useepplusfun.FindExcelFiles("DifficultyChoose"); hardNum = PlayerPrefs.GetInt("DifficultyType"); //难度值获取 }