/// <summary> /// 转换Excel文件 /// </summary> private static void Convert() { foreach (string assetsPath in excelList) { //获取Excel文件的绝对路径 string excelPath = pathRoot + "/" + assetsPath; //构造Excel工具类 ExcelUtility excel = new ExcelUtility(excelPath); //判断编码类型 Encoding encoding = null; if (indexOfEncoding == 0 || indexOfEncoding == 3) { encoding = Encoding.GetEncoding("utf-8"); } else if (indexOfEncoding == 1) { encoding = Encoding.GetEncoding("gb2312"); } //判断输出类型 string output = ""; if (indexOfFormat == 0) { output = excelPath.Replace(".xlsx", ".json"); excel.ConvertToJson(output, encoding); } else if (indexOfFormat == 1) { output = excelPath.Replace(".xlsx", ".csv"); excel.ConvertToCSV(output, encoding); } else if (indexOfFormat == 2) { output = excelPath.Replace(".xlsx", ".xml"); excel.ConvertToXml(output); } else if (indexOfFormat == 3) { output = excelPath.Replace(".xlsx", ".lua"); excel.ConvertToLua(output, encoding); } //判断是否保留源文件 if (!keepSource) { FileUtil.DeleteFileOrDirectory(excelPath); } //刷新本地资源 AssetDatabase.Refresh(); } //转换完后关闭插件 //这样做是为了解决窗口 //再次点击时路径错误的Bug instance.Close(); }
/// <summary> /// 转换Excel文件 /// </summary> private static void Convert() { foreach (string assetsPath in excelList) { //获取Excel文件的绝对路径 string excelPath = Application.dataPath.Replace("Assets", "") + assetsPath; //构造Excel工具类 ExcelUtility excel = new ExcelUtility(excelPath); //判断编码类型 Encoding encoding = null; if (indexOfEncoding == 0 || indexOfEncoding == 3) { encoding = Encoding.GetEncoding("utf-8"); } else if (indexOfEncoding == 1) { encoding = Encoding.GetEncoding("gb2312"); } //判断输出类型 string output = ""; if (indexOfFormat == 0) { output = excelPath.Replace(".xlsx", ".json"); excel.ConvertToJson(output, encoding); } else if (indexOfFormat == 1) { output = excelPath.Replace(".xlsx", ".csv"); excel.ConvertToCSV(output, encoding); } else if (indexOfFormat == 2) { output = excelPath.Replace(".xlsx", ".xml"); excel.ConvertToXml(output); } else if (indexOfFormat == 3) { output = excelPath.Replace(".xlsx", ".lua"); excel.ConvertToLua(output, encoding); } else if (indexOfFormat == 4) { output = excelPath.Replace(".xlsx", "CSV.cs"); excel.ConvertToCSharp(output, encoding); } //判断是否保留源文件 if (!keepSource) { FileUtil.DeleteFileOrDirectory(excelPath); } //刷新本地资源 AssetDatabase.Refresh(); } }