loudixvmuniu/Assets/Third/Excel/ExcelTools.cs

41 lines
1.3 KiB
C#
Raw Normal View History

2025-01-02 12:15:45 +08:00
#if UNITY_EDITOR
using System;
using System.IO;
using UnityEditor;
using UnityEngine;
using System.Text;
using System.Collections;
using System.Collections.Generic;
namespace CG.UTility
{
public static class ExcelTools
{
/// <summary>
/// 加载Excel
/// </summary>
[MenuItem("Tools/ExcelTools", false, 4)]
private static void LoadExcel()
{
string[] excelList = Directory.GetFiles(Application.streamingAssetsPath + ConstCtrl.EXCEL_PATH, "*.xlsx");
for (int i = 0; i < excelList.Length; i++)
{
Convert(excelList[i]);
}
}
/// <summary>
/// 转换Excel文件
/// </summary>
private static void Convert(string excelFile)
{
//构造Excel工具类
ExcelUtility excel = new ExcelUtility(excelFile);
excel.ConvertToJson(Application.streamingAssetsPath + ConstCtrl.JSON_PATH+ Path.GetFileNameWithoutExtension(excelFile)+".txt", Encoding.GetEncoding("utf-8"));
excel.ConvertToCSharp(Application.streamingAssetsPath + ConstCtrl.CSHARP_PATH + Path.GetFileNameWithoutExtension(excelFile) + ".cs", Encoding.GetEncoding("utf-8"));
//刷新本地资源
AssetDatabase.Refresh();
}
}
}
#endif