Ejemplo n.º 1
0
        private static int GetCellTxt(ExcelMapData data, StringBuilder v_sb, int v_layer)
        {
            if (v_layer > Separator.Length)
            {
                Debug.Error("层数超过了上限");
            }
            if (data.IsLeafe)
            {
                v_sb.Append(data.LeafVal.GetTxtValue());
                return(0);
            }
            List <KeyValue <ExcelMapData> > childDatas = data.GetKeyValues();

            if (childDatas == null)
            {
                return(0);
            }
            int deep = 0;

            for (int i = 0; i < childDatas.Count; i++)
            {
                if (i > 0)
                {
                    v_sb.Append(Separator[deep - 1]);
                }
                deep = Math.Max(deep, GetCellTxt(childDatas[i].val, v_sb, v_layer + 1) + 1);
            }
            return(deep);
        }
Ejemplo n.º 2
0
        private static void _translate(ExcelMapData v_src, LuaTable v_dst, bool v_bSingleKey = false)
        {
            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;
                switch (data.Type)
                {
                case EExcelMapDataType.indexMap:
                    LuaMap indexMap = new LuaMap();
                    indexMap.init(true, ExportSheetBin.ROW_MAX_ELEMENT);
                    v_dst.addData(key, indexMap);
                    _translate(data, indexMap, v_bSingleKey);
                    indexMap.Note = data.Note;
                    break;

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

                case EExcelMapDataType.cellTable:
                    LuaTable cellTable;
                    if (data.IsArray)
                    {
                        cellTable = new LuaArray();
                        ((LuaArray)cellTable).init(false, true, ExportSheetBin.ROW_MAX_ELEMENT);
                    }
                    else
                    {
                        cellTable = new LuaMap();
                        ((LuaMap)cellTable).init(false, ExportSheetBin.ROW_MAX_ELEMENT);
                    }
                    v_dst.addData(key, cellTable);
                    _translate(data, cellTable);
                    cellTable.Note = data.Note;
                    break;

                case EExcelMapDataType.cellData:
                    LuaValue leafVal = data.LeafVal.GetLuaValue();
                    v_dst.addData(key, leafVal);
                    leafVal.Note = data.Note;
                    break;
                }
            }
        }
Ejemplo n.º 3
0
        private static void _translate(ExcelMapData v_src, StringBuilder v_dst, TxtExportHeader[] listFieldName)
        {
            StringBuilder lineBuilder = new StringBuilder();
            StringBuilder cellBuilder = new StringBuilder();
            List <KeyValue <ExcelMapData> > childDatas = v_src.GetKeyValues();

            for (int i = 0; i < childDatas.Count; i++)      //行
            {
                lineBuilder.Clear();
                ExcelMapData data = childDatas[i].val;
                if (data.Type != EExcelMapDataType.rowData)
                {
                    continue;
                }
                List <KeyValue <ExcelMapData> > childDatas2 = data.GetKeyValues();

                for (int j = 0; j < listFieldName.Length; j++)  //每一列
                {
                    if (lineBuilder.Length > 0)
                    {
                        lineBuilder.Append("\t");
                    }

                    int childIdx = _findChild(listFieldName[j].Name, childDatas2);

                    if (childIdx >= 0)
                    {
                        StringBuilder sb = new StringBuilder();
                        GetCellTxt(childDatas2[childIdx].val, sb, 0);
                        lineBuilder.Append(sb);
                    }
                    else
                    {
                        lineBuilder.Append(listFieldName[j].GetDefaultVal());
                    }
                }
                v_dst.Append(lineBuilder);
                v_dst.Append("\r\n");
            }
        }
Ejemplo n.º 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());
                }
            }
        }