| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- public static class ExcelHandler
- {
- /// <summary>
- /// 读取 Excel 中第一列
- /// </summary>
- public static List<string> ReadFirstColumn(string deviceName)
- {
- List<string> list = new List<string>();
- string path = PathHelper.CombineFilePath(PathHelper.m_ReadOnlyPath, deviceName) + GlobalConfig.excelSuffix;
- if (!File.Exists(path))
- {
- Debug.LogError("Excel 文件不存在:" + path);
- return list;
- }
- List<MoveData> rows = ExcelHelper.ReadInfoFromExcel<MoveData>(path, 1);
- if (rows == null || rows.Count == 0) return list;
- HashSet<string> seen = new HashSet<string>();
- foreach (var r in rows)
- {
- if (string.IsNullOrEmpty(r.moveName)) continue;
- if (seen.Add(r.moveName)) list.Add(r.moveName);
- }
- return list;
- }
- /// <summary>
- /// 写回 Excel 第一列(名字顺序)
- /// </summary>
- public static void WriteFirstColumn(string deviceName, List<string> names)
- {
- string path = PathHelper.CombineFilePath(PathHelper.m_ReadOnlyPath, deviceName) + GlobalConfig.excelSuffix;
- List<MoveData> list = new List<MoveData>();
- foreach (var n in names) list.Add(new MoveData { moveName = n });
- ExcelHelper.WriteInfoToExcel(path, list);
- Debug.Log($"已写回 Excel 顺序:{path}({names.Count} 条)");
- }
- }
|