예제 #1
0
        protected override JsonValue _OnGetJsonValue()
        {
            JsonMap mp = new JsonMap();

            mp.init(false, ExportSheetBin.ROW_MAX_ELEMENT);
            return(mp);
        }
예제 #2
0
        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);
        }
예제 #3
0
        public static JsonTable GetJsonTable(ExcelMapData v_root)
        {
            JsonTable luaRoot = null;

            if (v_root.IsArray)
            {
                luaRoot = new JsonArray();
                ((JsonArray)luaRoot).init(true, ExportSheetBin.ROW_MAX_ELEMENT);
            }
            else
            {
                luaRoot = new JsonMap();
                ((JsonMap)luaRoot).init(true, ExportSheetBin.ROW_MAX_ELEMENT);
            }
            _translate(v_root, luaRoot);
            return(luaRoot);
        }
예제 #4
0
        private static void _translate(ExcelMapData v_src, JsonTable v_dst)
        {
            List <KeyValue <ExcelMapData> > childDatas = v_src.GetKeyValues();

            for (int i = 0; i < childDatas.Count; i++)
            {
                KeyValue <ExcelMapData> child = childDatas[i];
                Key          key  = child.key;
                ExcelMapData data = child.val;
                try
                {
                    switch (data.Type)
                    {
                    case EExcelMapDataType.indexMap:
                        JsonTable indexMap = null;
                        if (data.IsArray)
                        {
                            indexMap = new JsonArray();
                            ((JsonArray)indexMap).init(true, ExportSheetBin.ROW_MAX_ELEMENT);
                        }
                        else
                        {
                            indexMap = new JsonMap();
                            ((JsonMap)indexMap).init(true, ExportSheetBin.ROW_MAX_ELEMENT);
                        }
                        v_dst.addData(key, indexMap);
                        _translate(data, indexMap);
                        break;

                    case EExcelMapDataType.rowData:
                        JsonMap rowData = new JsonMap();
                        rowData.init(false, ExportSheetBin.ROW_MAX_ELEMENT);
                        v_dst.addData(key, rowData);
                        _translate(data, rowData);
                        break;

                    case EExcelMapDataType.cellTable:
                        JsonTable cellTable;
                        if (data.IsArray)
                        {
                            cellTable = new JsonArray();
                            ((JsonArray)cellTable).init(false, ExportSheetBin.ROW_MAX_ELEMENT);
                        }
                        else
                        {
                            cellTable = new JsonMap();
                            ((JsonMap)cellTable).init(false, ExportSheetBin.ROW_MAX_ELEMENT);
                        }
                        v_dst.addData(key, cellTable);
                        _translate(data, cellTable);
                        break;

                    case EExcelMapDataType.cellData:
                        JsonValue leafVal = data.LeafVal.GetJsonValue();
                        v_dst.addData(key, leafVal);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Debug.Exception("在添加{0}时发生错误,错误信息是:\r\n{1}", key, ex.ToString());
                }
            }
        }