Ejemplo n.º 1
0
        private static SearchKey GetGroupedSearchKey(TplBlock block, TplLine line)
        {
            SearchKey searchKey = null;
            SearchKey nextKey   = null;

            //水平分组查找同行
            foreach (var cell in line.CellList)
            {
                if (cell.GroupAlign == GroupAlign.Vertical)
                {
                    var cellVGroupKey = new SearchKey {
                        KeyName = cell.TplGroupColumnName
                    };

                    if (searchKey == null)
                    {
                        searchKey = cellVGroupKey;
                    }

                    if (nextKey == null)
                    {
                        nextKey = cellVGroupKey;
                    }
                    else
                    {
                        //递进赋值NextKey
                        nextKey.NextKey = cellVGroupKey;
                        nextKey         = cellVGroupKey;
                    }
                }
            }
            //垂直分组遍历Block行查找同列
            foreach (var vLine in block.TplLineList)
            {
                if (vLine.CellList.Count > line.CellList.Count)
                {
                    var cell = vLine.CellList[line.CellList.Count];
                    if (cell.GroupAlign == GroupAlign.Horizontal)
                    {
                        var cellHGroupKey = new SearchKey {
                            KeyName = cell.TplGroupColumnName
                        };
                        if (searchKey == null)
                        {
                            searchKey = cellHGroupKey;
                        }
                        if (nextKey == null)
                        {
                            nextKey = cellHGroupKey;
                        }
                        else
                        {
                            nextKey.NextKey = cellHGroupKey;
                            nextKey         = cellHGroupKey;
                        }
                    }
                }
            }
            return(searchKey);
        }
Ejemplo n.º 2
0
        private static TplLine ParseLine(Worksheet sheet, TplBlock block, int startCol, int startRow)
        {
            var colCount = block.ColumnsCount;
            var line     = new TplLine
            {
                TplRange = RangeHelper.GetRange(sheet, startCol, startRow, colCount, 1)
            };

            for (var i = 0; i < colCount; i++)
            {
                var range = RangeHelper.GetCell(sheet, startCol + i, startRow);
                var cell  = new TplCell
                {
                    TplRange     = range,
                    LastColIndex = i + startCol
                };
                var str = range.Value2 as string;
                if (!string.IsNullOrEmpty(str))
                {
                    ParseCell(block, line, cell, str.Trim());
                }
                line.CellList.Add(cell);
            }
            return(line);
        }
Ejemplo n.º 3
0
 private void FillLastLine(int currentLineIndex, TplLine updateLine, int rowIndex, DataTable table,
                           int valueIndex)
 {
     if (updateLine != null)
     {
         updateLine.UpdateRowData(Holder, rowIndex, table, valueIndex);
         if (UpdateAllRow)
         {
             for (var i = 0; i <= currentLineIndex; i++)
             {
                 var line = TplLineList[i];
                 if (line.ContainsHGroup && (line.InsertedRowList.Count > 0))
                 {
                     line.UpdateRowData(Holder, line.InsertedRowList[line.InsertedRowList.Count - 1], table,
                                        valueIndex);
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
        private static GroupValueSearchKey ParseCellFormulaGroupKey(TplBlock block, TplLine line, string formulaName,
                                                                    string pairValue)
        {
            var groupKey = new GroupValueSearchKey
            {
                Formula = formulaName
            };

            var valueKeyArray = pairValue.Trim()
                                .Split(new[] { TemplateFlags.CellValueKeySpliter }, StringSplitOptions.RemoveEmptyEntries);

            SearchKey nextKey = null;

            for (var i = 0; i < valueKeyArray.Length; i++)
            {
                //GroupKey筛选固定值时
                var valueFixedArray = valueKeyArray[i].Split(new[] { TemplateFlags.CellValueFixedSpliter },
                                                             StringSplitOptions.RemoveEmptyEntries);

                if (i == 0)
                {
                    //第一项Key作为绑定关联列名
                    groupKey.ValueColName = valueFixedArray[0].Trim().ToUpper();
                }
                else
                {
                    var searchKey = new SearchKey
                    {
                        KeyName = valueFixedArray[0].Trim().ToUpper()
                    };
                    if (valueFixedArray.Length > 1)
                    {
                        //包含=号赋固定值
                        searchKey.IsFixedValue = true;
                        searchKey.KeyValue     = valueFixedArray[1];
                    }
                    if (searchKey.KeyName == TemplateFlags.CellGroupKeySearchPattern)
                    {
                        //从之前添加的分组cells中查找
                        searchKey = GetGroupedSearchKey(block, line);
                        if (searchKey == null)
                        {
                            continue;
                        }
                    }
                    if (nextKey == null)
                    {
                        groupKey.SearchKey = searchKey;
                        nextKey            = searchKey;
                    }
                    else
                    {
                        nextKey.NextKey = searchKey;
                        nextKey         = searchKey;
                    }

                    //nextKey置尾,后续值追加到searchKey尾部
                    while (nextKey.NextKey != null)
                    {
                        nextKey = nextKey.NextKey;
                    }
                }
            }

            return(groupKey);
        }
Ejemplo n.º 5
0
        private static void ParseCell(TplBlock block, TplLine line, TplCell cell, string text)
        {
            text = text.Trim();
            if (text.StartsWith("R1C1:"))
            {
                cell.UseR1C1Formula = true;
                cell.TplTextContent = text.Substring(5);
            }
            else if (text[0] != TemplateFlags.CellStart)
            {
                cell.TplTextContent = text;
            }
            else
            {
                var index = text.IndexOf(TemplateFlags.CellEnd);
                if (index > 0)
                {
                    if ((index + 1) != text.Length)
                    {
                        cell.TplTextContent = text.Substring(index + 1);
                    }
                    text = text.Substring(1, index - 1);
                }
                cell.TplValueColName = text;
                var pair = ParseKeyValuePair(text);
                cell.TplFormat = GetPairValue(pair, TemplateFlags.CellFormat);
                if (!string.IsNullOrEmpty(cell.TplFormat))
                {
                    cell.TplFormat = cell.TplFormat.ToLower();
                }
                cell.MergeOption = ParseMergeOption(GetPairValue(pair, TemplateFlags.CellMergeOption));

                #region CellGroupAlign

                if (GetPairValue(pair, TemplateFlags.CellVGroup) != null)
                {
                    cell.GroupAlign         = GroupAlign.Vertical;
                    cell.TplGroupColumnName = GetPairValue(pair, TemplateFlags.CellVGroup).Trim().ToUpper();

                    Console.WriteLine(
                        string.Format("Contains Vg GroupColName:{0}", cell.TplGroupColumnName));
                }
                else if (GetPairValue(pair, TemplateFlags.CellHGroup) != null)
                {
                    cell.GroupAlign         = GroupAlign.Horizontal;
                    cell.TplGroupColumnName = GetPairValue(pair, TemplateFlags.CellHGroup).ToUpper();
                    line.ContainsHGroup     = true;
                    var insertOption = GetLineInsertOption(GetPairValue(pair, TemplateFlags.CellHGroupOption));
                    if ((insertOption != InsertOption.AfterChange) &&
                        (insertOption != InsertOption.BeforeChange))
                    {
                        insertOption = InsertOption.AfterChange;
                    }
                    cell.HgOption = insertOption;

                    Console.WriteLine(
                        string.Format("Contains Hg GroupColName:{0},LineInsertOption:{1}", cell.TplGroupColumnName,
                                      insertOption));
                }

                #endregion CellGroupAlign

                var pairValue = GetPairValue(pair, TemplateFlags.CellValue);
                if (string.IsNullOrEmpty(pairValue))
                {
                    if (!string.IsNullOrEmpty(cell.TplGroupColumnName))
                    {
                        //无值(v)标记时以分组列字段绑定
                        cell.TplValueColName = cell.TplGroupColumnName;
                    }
                }
                else
                {
                    cell.TplDefaultContent = GetPairValue(pair, TemplateFlags.CellDefaultContent);

                    if (ParseCellFormula(cell, ref pairValue))
                    {
                        var groupKey = ParseCellFormulaGroupKey(block, line, cell.Formula.Formula, pairValue);

                        Console.WriteLine(groupKey.ToString());

                        cell.Formula.KeyList.Add(groupKey);
                        block.GroupKeyList.Add(groupKey.Copy());
                    }
                }
            }
        }