public static OptData getExportContent(ExcelToMapData v_data, int v_optCode, string[] rootPath, string fileName) { OptData rtn = new OptData(); StringBuilder sb = new StringBuilder(); try { JsonMap root = new JsonMap(); root.init(true); JsonTable data = GetJsonTable(v_data._data); root.addData(new Key("data"), data); root.addData(new Key("excelName"), new JsonString(v_data.excelName)); root.outputValue(sb, 0); } catch (Exception ex) { rtn.errList.Add("导出基础数据时出现错误,错误信息为:\r\n" + ex.ToString()); } rtn.content = sb.ToString(); for (int i = 0; i < rootPath.Length; i++) { string opt_path = rootPath[i] + fileName; File.WriteAllText(opt_path, rtn.content); } return(rtn); }
public static StringBuilder GetTxtTable(ExcelToMapData v_data) { StringBuilder v_dst = new StringBuilder(); List <TxtExportHeader> listFieldName = new List <TxtExportHeader>(); //v_data.sheet_bins[0].header.GetTxtHeader(v_dst, listFieldName); TxtExportHeader[] headerNames = v_data.sheet_bins[0].header.MyGetTxtHeader(listFieldName); string[] name = new string[headerNames.Length]; for (int i = 0; i < headerNames.Length; i++) { name[i] = headerNames[i].Name; } v_dst.AppendLine(string.Join("\t", name)); string[] headType = new string[headerNames.Length]; for (int i = 0; i < headerNames.Length; i++) { headType[i] = headerNames[i].Type; } v_dst.AppendLine(string.Join("\t", headType)); _translate(v_data._data, v_dst, headerNames); return(v_dst); }
public static OptData getExportContent(ExcelToMapData v_data, int v_optCode, string[] rootPath, string fileName) { OptData rtn = new OptData(); StringBuilder sb; try { sb = GetTxtTable(v_data); } catch (Exception ex) { rtn.errList.Add("导出基础数据时出现错误,错误信息为:\r\n" + ex.ToString()); return(rtn); } rtn.content = sb.ToString(); for (int i = 0; i < rootPath.Length; i++) { string opt_path = rootPath[i] + fileName; File.WriteAllText(opt_path, rtn.content); } return(rtn); }
public static OptData getExportContent(ExcelToMapData v_data, int v_optCode, string[] rootPath, string fileName) { OptData rtn = new OptData(); StringBuilder sb = new StringBuilder(); try { LuaMap root = GetLuaTable(v_data._data, v_data.IsSingleKey); sb.Append("--[[\r\n"); sb.AppendFormat("output from excel {0}\r\n", v_data.excelName); v_data.opt_note(sb, "note"); sb.Append("\r\n"); sb.Append("colums:\r\n"); v_data.opt_colum_notes(sb, v_optCode); sb.Append("\r\n"); sb.Append("primary key:\r\n"); for (int i = 0; i < v_data.sheet_bins.Count; i++) { sb.AppendFormat("#{0} [{1}]: ", i, v_data.sheet_bins[i].sheetName); sb.Append(string.Join(",", v_data.sheet_bins[i].indexData.pmKey)); sb.Append("\r\n"); } sb.Append("]]\r\n"); sb.Append("local _T = LangUtil.Language\r\n"); if (v_data.IsDataPersistence) { sb.AppendFormat("if ddt[\"{0}\"] ~= nil then\r\n\treturn ddt[\"{0}\"]\r\nend\r\n", v_data.className); sb.Append("local data = "); root.outputValue(sb, 0); sb.AppendLine(); sb.AppendFormat("ddt[\"{0}\"] = data\r\n", v_data.className); //sb.Append("SetLooseReadonly(data)\r\n"); sb.Append("return data"); } else { sb.Append("return"); root.outputValue(sb, 0); } } catch (Exception ex) { rtn.errList.Add("导出基础数据时出现错误,错误信息为:\r\n" + ex.ToString()); } rtn.content = sb.ToString(); for (int i = 0; i < rootPath.Length; i++) { string opt_path = rootPath[i] + fileName; File.WriteAllText(opt_path, rtn.content); } return(rtn); //sb.Append(string.Format("\r\nreturn {0}", curIndex.className)); }
public static OptData getExportContent(ExcelToMapData v_data, int v_optCode) { OptData rtn = new OptData(); StringBuilder sb = new StringBuilder(); try { LuaMap root = GetLuaTable(v_data._data); sb.Append("--[[\r\n"); v_data.opt_note(sb, "note"); sb.Append("\r\n"); sb.Append("colums:\r\n"); v_data.opt_colum_notes(sb); sb.Append("\r\n"); sb.Append("primary key:\r\n"); for (int i = 0; i < v_data.sheet_bins.Count; i++) { sb.AppendFormat("#{0} [{1}]: ", i, v_data.sheet_bins[i].sheetName); sb.Append(string.Join(",", v_data.sheet_bins[i].indexData.pmKey)); sb.Append("\r\n"); } sb.Append("]]\r\n"); if (v_data.IsDataPersistence) { sb.AppendFormat("if ddt[v_data.className] ~= nil then\r\n\treturn {0}\r\nend\r\n", v_data.className); sb.AppendFormat("local {0} = ", v_data.className); root.outputValue(sb, 0); sb.AppendLine(); sb.AppendFormat("ddt[v_data.className] = {0}\r\n", v_data.className); sb.AppendFormat("SetLooseReadonly({0})\r\n", v_data.className); sb.AppendFormat("return {0}", v_data.className); } else { sb.Append("return"); root.outputValue(sb, 0); } } catch (Exception ex) { rtn.errList.Add("导出基础数据时出现错误,错误信息为:\r\n" + ex.ToString()); } rtn.content = sb.ToString(); return(rtn); //sb.Append(string.Format("\r\nreturn {0}", curIndex.className)); }
public static OptData getExportContent(ExcelToMapData v_data, int v_optCode) { OptData rtn = new OptData(); StringBuilder sb = new StringBuilder(); try { JsonTable root = GetJsonTable(v_data._data); root.outputValue(sb, 0); } catch (Exception ex) { rtn.errList.Add("导出基础数据时出现错误,错误信息为:\r\n" + ex.ToString()); } rtn.content = sb.ToString(); return(rtn); }
public void apposeReadExcel(string v_filePath) { Excel.Workbook book = new Excel.Workbook(v_filePath); Excel.Worksheet index_sheet = book.Worksheets["INDEX"]; if (index_sheet == null) { __old_readExcel(v_filePath); return; } //读取索引表 List <IndexSheetData> indexes = new List <IndexSheetData>(); SheetHeader index_header = new SheetHeader(); index_header.readHeader(index_sheet); Excel.Cells datas = index_sheet.Cells; for (int i = 1; i < 100; i++) { try { if (datas[i, 0].Value == null || string.IsNullOrEmpty(datas[i, 0].Value.ToString())) { break; } IndexSheetData the_index = new IndexSheetData(); the_index.init(datas, i, index_header); indexes.Add(the_index); } catch (Exception ex) { Debug.Error("{0}读取索引列,第{1}行时报错,报错信息如下\r\n{2}", Path.GetFileName(v_filePath), i + 2, ex.ToString()); return; } } Dictionary <string, ExcelToMapData>[] table_memo = new Dictionary <string, ExcelToMapData> [2]; Dictionary <string, ExportSheetBin>[] sheetBin_memo = new Dictionary <string, ExportSheetBin> [2]; string[] root_pathes = { Config.cliPath, Config.servPath }; int[] optCode = { 1, 2 }; for (int i = 0; i < table_memo.Length; i++) { table_memo[i] = new Dictionary <string, ExcelToMapData>(); sheetBin_memo[i] = new Dictionary <string, ExportSheetBin>(); } //根据索引表读取各sheet foreach (IndexSheetData curIndex in indexes) { if (!curIndex.isOpt) { continue; } Excel.Worksheet curSheet = book.Worksheets[curIndex.sheetName]; if (curSheet == null) { Debug.Error("{0}没有找到sheet[{1}]", Path.GetFileName(v_filePath), curIndex.sheetName); return; } ExportSheetBin sheetBin = new ExportSheetBin(); try { if (!sheetBin.init(curSheet, curIndex)) { return; } } catch (Exception ex) { Debug.Error("{0}_[{1}]导出基础数据时出现错误,错误信息为:\r\n{2}", Path.GetFileNameWithoutExtension(v_filePath), curIndex.sheetName, ex.ToString()); return; } //根据服务端的文件名,创建获取luamap string[] file_names = { curIndex.optCliFileName, curIndex.optSrvFileName }; for (int i = 0; i < table_memo.Length; i++)//客户端服务端各生成一遍 { if (string.IsNullOrEmpty(file_names[i])) { continue; } if (!table_memo[i].ContainsKey(file_names[i])) { ExcelMapData new_map = new ExcelMapData(); bool isDataPersistence = curIndex.isDataPersistence && (!string.IsNullOrEmpty(curIndex.optCliFileName)) && curIndex.optCliFileName.EndsWith(".lua"); ExcelToMapData new_data = new ExcelToMapData(new_map, isDataPersistence, Path.GetFileNameWithoutExtension(file_names[i])); table_memo[i].Add(file_names[i], new_data); } if (!sheetBin_memo[i].ContainsKey(file_names[i])) { sheetBin_memo[i].Add(file_names[i], sheetBin); } ExcelToMapData root_table = table_memo[i][file_names[i]]; root_table.add_sheetbin(sheetBin); //把表中的数据读取到lua map里 //应当把这里的逻辑改为,把表中数据读到一个map_data中,而后转到各语言的结构中 try { sheetBin.getExportMap(root_table._data, optCode[i]); } catch (Exception ex) { Debug.Error("在装载【{0}】数据到中间结构时发生错误,错误信息是{1}", curIndex.sheetName, ex.ToString()); } } } //这里应当写为,根据后缀名导出不同的语言 for (int i = 0; i < table_memo.Length; i++) { foreach (var cur_pair in table_memo[i]) { string opt_path = root_pathes[i] + cur_pair.Key; OptData optData = null; ExportSheetBin cur_sheetBin = sheetBin_memo[i][cur_pair.Key]; ELanguage optLanguage = cur_sheetBin.indexData.getOptLanguage(i); bool skip = false; switch (optLanguage) { case ELanguage.lua: optData = LuaExporter.getExportContent(cur_pair.Value, optCode[i]); break; case ELanguage.json: optData = JsonExporter.getExportContent(cur_pair.Value, optCode[i]); break; case ELanguage.xml: Debug.Error("xml导出未实现"); break; case ELanguage.none: skip = true; break; default: Debug.Error("未知导出语言"); break; } if (!skip) { if (optData.errList.Count > 0) { Debug.Error(string.Format("在导出{0}时发生错误:\r\n", cur_pair.Key) + optData.getErrInfo()); return; } File.WriteAllText(opt_path, optData.content); //todo 如果是Realease模式,把文件输出到一个临时文件夹,调用LUAC,把lua文件生成到配置的cli文件夹中。 } } } Debug.Info("{0}:导表完成~~~", Path.GetFileName(v_filePath)); }