Esempio n. 1
0
        public void opt_colum_notes(StringBuilder v_sb)
        {
            Dictionary <string, string> headers = new Dictionary <string, string>();

            for (int i = 0; i < sheet_bins.Count; i++)
            {
                ExportSheetBin        esb = sheet_bins[i];
                ExcelHeaderDecorate[] hds = esb.header.HeaderDecorates;
                for (int j = 0; j < hds.Length; j++)
                {
                    if (!headers.ContainsKey(hds[j].FullName))
                    {
                        headers.Add(hds[j].FullName, hds[j].Chinese);
                    }
                }
            }
            StringBuilder cursb = new StringBuilder();

            foreach (var data in headers)
            {
                if (cursb.Length > 0)
                {
                    cursb.Append(" ,");
                }
                cursb.AppendFormat("{{{0},{1}}}", data.Key, data.Value);
            }
            v_sb.Append(cursb);
        }
Esempio n. 2
0
        public int GetFieldCount()
        {
            Dictionary <string, string> headers = new Dictionary <string, string>();

            for (int i = 0; i < sheet_bins.Count; i++)
            {
                ExportSheetBin        esb = sheet_bins[i];
                ExcelHeaderDecorate[] hds = esb.header.HeaderDecorates;
                for (int j = 0; j < hds.Length; j++)
                {
                    string[] strs = hds[j].FullName.Split('[');
                    if (!headers.ContainsKey(strs[0]))
                    {
                        headers.Add(strs[0], hds[j].Chinese);
                    }
                }
            }
            return(headers.Count);
        }
Esempio n. 3
0
 public void add_sheetbin(ExportSheetBin v_sheetbin)
 {
     sheet_bins.Add(v_sheetbin);
 }
Esempio n. 4
0
        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));
        }