/// <summary> /// 通过excel生成class /// </summary> /// <param name="excelFilePath"></param> static private void GenClassByExcel(string outputDirectory, string excelFilePath, string localOrServer) { Debug.LogFormat("[{0}]正在生成:" + excelFilePath, localOrServer); var excel = new ExcelUtility(excelFilePath); int idX = -1; int idY = -1; List <object> keepFieldList = new List <object>(); string json = excel.GetJson(localOrServer, ref idX, ref idY, ref keepFieldList); if (idX != -1 && idY != -1) { if (idY < 2) { Debug.LogErrorFormat("【生成失败】 {0} ,请检查表头预留3行:备注,类型,字段名!", Path.GetFileName(excelFilePath)); return; } //这里将前三列进行判断 var statements = excel.GetRowDatas(idY - 2); var fieldTypes = excel.GetRowDatas(idY - 1); if (idX > 0) { statements.RemoveRange(0, idX); fieldTypes.RemoveRange(0, idX); if (keepFieldList.Count > 0) { keepFieldList.RemoveRange(0, idX); } } if (keepFieldList.Count > 0) { for (int i = keepFieldList.Count - 1; i >= 0; i--) { if (!keepFieldList[i].Equals("*")) { statements.RemoveAt(i); fieldTypes.RemoveAt(i); } } } var clsContent = Json2Class(excelFilePath, json, localOrServer, statements, fieldTypes); //输出目录控制 string outputFile = outputDirectory + "/" + localOrServer; outputFile = Path.Combine(outputFile, Path.GetFileName(excelFilePath) + ".cs"); FileHelper.WriteAllText(outputFile, clsContent); Debug.LogFormat("<color=red> [{0} 成功] </color>:{1}", localOrServer, excelFilePath); } else { Debug.LogError("不符合规范内容:" + excelFilePath); } }
/// <summary> /// 通过excel生成class /// </summary> /// <param name="filename"></param> static private void GenClassByExcel(string filename, string dbType) { Debug.LogFormat("[{0}]正在生成:" + filename, dbType); var excel = new ExcelUtility(filename); int idX = -1; int idY = -1; List <object> keepFieldList = new List <object>(); string json = excel.GetJson(dbType, ref idX, ref idY, ref keepFieldList); if (idX != -1 && idY != -1) { if (idY < 2) { Debug.LogErrorFormat("【生成失败】 {0} ,请检查表头预留3行:备注,类型,字段名!", Path.GetFileName(filename)); return; } //这里将前三列进行判断 var statements = excel.GetRowDatas(idY - 2); var fieldTypes = excel.GetRowDatas(idY - 1); if (idX > 0) { statements.RemoveRange(0, idX); fieldTypes.RemoveRange(0, idX); if (keepFieldList.Count > 0) { keepFieldList.RemoveRange(0, idX); } } if (keepFieldList.Count > 0) { for (int i = keepFieldList.Count - 1; i >= 0; i--) { if (!keepFieldList[i].Equals("*")) { statements.RemoveAt(i); fieldTypes.RemoveAt(i); } } } Json2Class(filename, json, dbType, statements, fieldTypes); Debug.LogFormat("<color=red> [{0} 成功] </color>:{1}", dbType, filename); } else { Debug.LogError("不符合规范内容:" + filename); } }