public void add_header(ExcelHeaderDecorate v_header, bool v_isSkip = false) { if (m_header_dct_idx.ContainsKey(v_header.FullName)) { Debug.Exception("出现了重复的表头——{0}", v_header.FullName); return; } m_header_dct.Add(v_header); m_header_dct_idx.Add(v_header.FullName, m_header_dct.Count - 1); ComplexExcelHeaderNode loc = _get_header_Decorate(v_header.FullName, true); loc.LeafDataIdx = m_header_dct.Count - 1; loc.IsSkip = v_isSkip; }
private void _get_row_data(Serchdata v_st, CellValue[] v_row_data, int v_optCode) { ExcelMapData curmap = v_st.curmap; ComplexExcelHeaderNode parrent = v_st.node; List <KeyValue <ComplexExcelHeaderNode> > keyValSet = v_st.node.getKeyValueSet(); for (int i = 0; i < keyValSet.Count; i++) { Key the_key = keyValSet[i].key; ComplexExcelHeaderNode node = parrent.get_node(the_key); if (node.IsSkip) { continue; } if (node.IsLeaf) { ExcelHeaderDecorate ehd = m_header_dct[node.LeafDataIdx]; if (!ehd.is_need_opt(v_optCode)) { continue; } CellValue celldata = v_row_data[node.LeafDataIdx]; if (!celldata._isMiss) { ExcelMapData leafData = new ExcelMapData(); leafData.initAsLeafeData(celldata); leafData.Type = EExcelMapDataType.cellData; curmap.addData(the_key, leafData); } } else { ExcelMapData map_next = new ExcelMapData(); map_next.initAsTableData(); map_next.Type = EExcelMapDataType.cellTable; Serchdata sdnew = new Serchdata(node, map_next); _get_row_data(sdnew, v_row_data, v_optCode); if (!map_next.IsEmpty()) { curmap.addData(the_key, map_next); } } } }
protected string getLastMul(ComplexExcelHeaderNode v_cur, out bool v_isOpt, int v_layer = 1) { var first = v_cur.getKeyValueSet()[0]; if (!first.val.IsLeaf) { return(getLastMul(first.val, out v_isOpt, v_layer + 1)); } else { v_isOpt = m_header_dct[first.val.LeafDataIdx].is_need_opt(2); if (!v_isOpt) { return(null); } StringBuilder sb = new StringBuilder(); if (m_header_dct[first.val.LeafDataIdx].DataStructure == ECellDataStructure.array) { sb.Append("mut,"); sb.Append(m_header_dct[first.val.LeafDataIdx].RealType); sb.Append("," + (v_layer + 1)); } else { sb.Append("mut,"); List <KeyValue <ComplexExcelHeaderNode> > subs = v_cur.getKeyValueSet(); for (int i = 0; i < subs.Count; i++) { if (m_header_dct[subs[i].val.LeafDataIdx] != null && m_header_dct[subs[i].val.LeafDataIdx].is_need_opt(2)) { if (i > 0) { sb.Append("#"); } sb.Append(m_header_dct[subs[i].val.LeafDataIdx].RealType); } } sb.Append("," + v_layer); } return(sb.ToString()); } }
public TxtExportHeader[] MyGetTxtHeader(List <TxtExportHeader> listFieldName) { List <KeyValue <ComplexExcelHeaderNode> > keyValSet = getKeyValueSet(); List <TxtExportHeader> header = new List <TxtExportHeader>(); for (int i = 0; i < keyValSet.Count; i++) { Key key = keyValSet[i].key; ComplexExcelHeaderNode node = keyValSet[i].val; if (node.IsLeaf) { if (!m_header_dct[node.LeafDataIdx].is_need_opt(2)) { continue; } TxtExportHeader teh; string subtype = m_header_dct[node.LeafDataIdx].RealType; if (m_header_dct[node.LeafDataIdx].DataStructure == ECellDataStructure.array) { teh = new TxtExportHeader(key.ToString(), string.Format("mut,{0}#{0},1", subtype)); } else { teh = new TxtExportHeader(key.ToString(), subtype); } header.Add(teh); } else { bool isOpt; string type = getLastMul(node, out isOpt); if (isOpt) { header.Add(new TxtExportHeader(key.ToString(), type)); } } } return(header.ToArray()); }
protected ComplexExcelHeaderNode _get_header_Decorate(string v_full_header, bool v_is_create = false) { string headerStr = v_full_header + '$'; int state = 0;//0表示正常状态,1表示数组状态,2表示]后的状态 ComplexExcelHeaderNode loc = this; StringBuilder cursb = new StringBuilder(); for (int i = 0; i < headerStr.Length; i++) { char curcha = headerStr[i]; switch (state) { case 0: switch (curcha) { case '[': loc = loc.get_node(cursb.ToString(), v_is_create); loc.debug_name = cursb.ToString(); cursb.Clear(); state = 1; break; case '.': loc = loc.get_node(cursb.ToString(), v_is_create); loc.debug_name = cursb.ToString(); cursb.Clear(); break; case '$': loc = loc.get_node(cursb.ToString(), v_is_create); loc.debug_name = cursb.ToString(); cursb.Clear(); break; default: cursb.Append(curcha); break; } break; case 1: if (char.IsDigit(curcha)) { cursb.Append(curcha); } else if (curcha == ']') { int index = Convert.ToInt32(cursb.ToString()); loc = loc.get_node(index, v_is_create); loc.debug_name = cursb.ToString(); cursb.Clear(); state = 2; } else { Debug.Exception("{0}中,在遍历到{1}位置时,发现{2}不是数字", v_full_header, i, curcha); return(null); } break; case 2: switch (curcha) { case '.': state = 0; break; case '[': state = 1; break; case '$': break; default: Debug.Exception("表头{0}语法错误", v_full_header); break; } break; } } return(loc); }
public Serchdata(ComplexExcelHeaderNode v_node, ExcelMapData v_map) { node = v_node; curmap = v_map; }