コード例 #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);
        }
コード例 #2
0
 /// <summary>
 /// 获取分组值
 /// </summary>
 /// <param name="holder"></param>
 /// <param name="table"></param>
 /// <param name="valueIndex"></param>
 /// <returns></returns>
 public object GetGroupValue(GroupDataHolder holder, DataTable table, int valueIndex)
 {
     if (ReusedKey == null)
     {
         ReusedKey = SearchKey.FindReusedKey(TplGroupColumnName);
     }
     return(ReusedKey.GetReusedValue(table, valueIndex));
 }
コード例 #3
0
        public int FillBlock(DataTable table)
        {
            var rowIndex = StartParseRowIndex;

            for (var i = 0; i < table.Rows.Count; i++)
            {
                CountedMap.Clear();
                if ((DynamicColumn != null) && !IsDynamicCloumnsCreated)
                {
                    DynamicColumn.CheckColumn(this, Holder, rowIndex, table, i);
                }
                foreach (var groupKey in GroupKeyList)
                {
                    if (groupKey.ReusedKey == null)
                    {
                        groupKey.ReusedKey = SearchKey.FindReusedKey(groupKey.ValueColName);
                    }
                    var copyKey = groupKey.Copy();
                    if (copyKey.SearchKey != null)
                    {
                        copyKey.SearchKey.FillKey(table, i);
                    }
                    Holder.AddValue(CountedMap, copyKey, table, i);
                }
                for (var k = 0; k < TplLineList.Count; k++)
                {
                    var updateLine = TplLineList[k];
                    var isNewLine  = updateLine.FillLine(Holder, rowIndex, table, i);
                    if (isNewLine)
                    {
                        FillLastLine(k, LastUsedLine, rowIndex - 1, table, LastUsedLineValueIndex); //?填充上一行值
                        LastUsedLine           = updateLine;
                        LastUsedLineValueIndex = i;
                        if ((i + 1) >= table.Rows.Count)
                        {
                            FillLastLine(k, updateLine, rowIndex, table, LastUsedLineValueIndex);
                        }

                        rowIndex  += 1;
                        RowsCount += 1;
                    }
                }
            }
            MergeHGroupCells();
            if (!table.ExtendedProperties.ContainsKey("TableType") ||
                (table.ExtendedProperties["TableType"].ToString() != "CustumEmpty"))
            {
                MergeVGroupCells();
            }
            return(RowsCount);
        }
コード例 #4
0
        private SearchKey Copy(bool copyValue)
        {
            var key = new SearchKey
            {
                KeyName   = KeyName,
                ReusedKey = ReusedKey
            };

            if (copyValue)
            {
                key.KeyValue     = KeyValue;
                key.IsFixedValue = IsFixedValue;
            }
            if (NextKey != null)
            {
                key.NextKey = NextKey.Copy(copyValue);
            }
            return(key);
        }
コード例 #5
0
        public void FillTemplate()
        {
            var now = DateTime.Now;

            foreach (var template in sheetList)
            {
                template.FillTemplate();
            }

            foreach (var template in sheetList)
            {
                template.Clear();
            }

            SearchKey.ClearKeyPool();

            #region Log

            foreach (var template in sheetList)
            {
                foreach (var block in template.BlockList)
                {
                    Console.WriteLine(string.Concat("Block: ", block.Name, " gKeyList: ", block.GroupKeyList.Count,
                                                    " ValueList: ", block.Holder.GroupValueDict.Count));

                    foreach (var pair in block.Holder.GroupValueDict)
                    {
                        Console.WriteLine("VV--" + pair.Key + "--" + pair.Value);
                    }
                }
            }
            Console.WriteLine("GetColVlaue Call Times: " + RangeHelper.GetColValueCount);
            Console.WriteLine("GetColVlaueByIndex Call Times: " + RangeHelper.GetColValueByIndexCount);

            Console.WriteLine(SearchKey.GetReusedKeyInfo());

            Console.WriteLine("GetRange Call Times: " + RangeHelper.GetRangeCallTimes);
            Console.WriteLine("UpdateCellValue Call Times: " + RangeHelper.GetRangeCallTimes);
            Console.WriteLine("insertCopyRange Call Times: " + RangeHelper.InsertCopyRangeCallTimes);
            Console.WriteLine("Total time: " + DateTime.Now.Subtract(now).TotalMilliseconds + "ms.");

            #endregion Log
        }
コード例 #6
0
 public void AddValue(Dictionary <GroupValueSearchKey, bool> map, GroupValueSearchKey groupKey, DataTable table,
                      int valueIndex)
 {
     if (!map.ContainsKey(groupKey))
     {
         object groupValue;
         if (groupKey.SearchKey != null)
         {
             for (var searchKey = groupKey.SearchKey; searchKey != null; searchKey = searchKey.NextKey)
             {
                 if (searchKey.ReusedKey == null)
                 {
                     searchKey.ReusedKey = SearchKey.FindReusedKey(searchKey.KeyName);
                 }
                 if (searchKey.IsFixedValue)
                 {
                     if (!Equals(searchKey.ReusedKey.GetReusedValue(table, valueIndex), searchKey.KeyValue))
                     {
                         return;
                     }
                 }
             }
         }
         if (!GroupValueDict.TryGetValue(groupKey, out groupValue))
         {
             groupValue = 0;
             GroupValueDict.Add(groupKey, groupValue);
         }
         if (groupKey.ReusedKey == null)
         {
             groupKey.ReusedKey = SearchKey.FindReusedKey(groupKey.ValueColName);
         }
         GroupValueDict[groupKey] = CalculateForumla(groupKey.Formula, groupValue,
                                                     groupKey.ReusedKey.GetReusedValue(table, valueIndex));
         map[groupKey] = true;
     }
 }
コード例 #7
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);
        }
コード例 #8
0
        public void InsertOneColumn(TplBlock block, int colIndex, GroupDataHolder holder, DataTable columnTalbe,
                                    int valueIndex, bool hasData)
        {
            if (hasData)
            {
                var range = RangeHelper.GetRange(TplRange.Worksheet, StartColIndex + colIndex, block.StartParseRowIndex,
                                                 1,
                                                 block.RowsCount);
                RangeHelper.InsertCopyRange(TplRange.Worksheet, range,
                                            (StartColIndex + GroupColumnCount) + InsertCount, block.StartParseRowIndex,
                                            1, block.RowsCount,
                                            InsertRangeDirection.Right, TplLastColumnIndex);
            }
            var orign = RangeHelper.GetRange(TplRange.Worksheet, StartColIndex + colIndex, block.TplRange.Row, 1,
                                             block.TplRowCount);

            RangeHelper.InsertCopyRange(TplRange.Worksheet, orign,
                                        (StartColIndex + GroupColumnCount) + InsertCount, orign.Row,
                                        1, block.TplRowCount,
                                        InsertRangeDirection.Right, TplLastColumnIndex);

            RefreshLineTplRanges(block, 1);
            block.TplColumCount++;
            block.ColumnsCount++;
            for (var i = 0; i < block.TplLineList.Count; i++)
            {
                var line    = block.TplLineList[i];
                var num2    = StartCellIndex + colIndex;
                var tplCell = line.CellList[num2].Copy();
                tplCell.LastColIndex++;
                line.CellList.Insert((StartCellIndex + GroupColumnCount) + InsertCount, tplCell);
                if (tplCell.Formula != null)
                {
                    foreach (var groupKey in tplCell.Formula.KeyList)
                    {
                        if (groupKey.ReusedKey == null)
                        {
                            groupKey.ReusedKey = SearchKey.FindReusedKey(groupKey.ValueColName);
                        }
                        for (var key3 = groupKey.SearchKey; key3 != null; key3 = key3.NextKey)
                        {
                            if (IsGroupedColumn(key3.KeyName))
                            {
                                key3.KeyValue     = RangeHelper.GetTableValue(columnTalbe, valueIndex, key3.KeyName);
                                key3.IsFixedValue = true;
                            }
                        }
                        block.GroupKeyList.Add(groupKey.Copy());
                        if (groupKey.SearchKey != null)
                        {
                            groupKey.SearchKey.FillKey(columnTalbe, valueIndex);
                        }
                        block.Holder.AddValue(block.CountedMap, groupKey, columnTalbe, valueIndex);
                    }
                }
                tplCell.GroupAlign = GroupAlign.None;
                Console.WriteLine(string.Concat("Inserted hg [", i.ToString().PadLeft(3), "][",
                                                num2.ToString().PadLeft(3), "] = ", tplCell.Formula));
                if (i < block.RowsCount)
                {
                    var currentCellRange = RangeHelper.GetCell(TplRange.Worksheet,
                                                               (StartColIndex + GroupColumnCount) + InsertCount,
                                                               block.StartParseRowIndex + i);
                    tplCell.WriteCell(Tpl, holder, currentCellRange, columnTalbe, valueIndex);
                }
            }
            InsertCount++;
        }