Beispiel #1
0
        /// <summary>
        /// 获取单元格显示值 优先级:公式->水平分组列添加值->数据源值
        /// </summary>
        /// <param name="holder"></param>
        /// <param name="table"></param>
        /// <param name="rowIndex"></param>
        /// <returns></returns>
        private object GetValue(GroupDataHolder holder, DataTable table, int rowIndex)
        {
            if (Formula != null)
            {
                return(Formula.GetValue(holder, table, rowIndex));
            }
            if (HgOption != InsertOption.Never)
            {
                return(TplTextContent); //插入动态列时更新赋值
            }
            var tableValue = RangeHelper.GetTableValue(table, rowIndex, TplValueColName);

            return(tableValue ?? TplTextContent);
        }
Beispiel #2
0
        private int IsNeedNewCol(DataTable table, int valueIndex)
        {
            var objArray = new object[GroupColList.Count];

            for (var i = 0; i < GroupColList.Count; i++)
            {
                var colName = GroupColList[i];
                objArray[i] = RangeHelper.GetTableValue(table, valueIndex, colName);
            }
            if (LastValueMap.Any(objArray2 => CompareArray(objArray, objArray2)))
            {
                return(-1);
            }
            LastValueMap.Add(objArray);
            return(0);
        }
Beispiel #3
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++;
        }
Beispiel #4
0
        public void InsertColumn(TplBlock block, GroupDataHolder holder, DataTable dataTable, int valueIndex,
                                 bool hasData)
        {
            if (InsertCount > 0)
            {
                if (hasData)
                {
                    var range = RangeHelper.GetRange(TplRange.Worksheet,
                                                     (StartColIndex + InsertCount) - GroupColumnCount, block.StartParseRowIndex,
                                                     GroupColumnCount, block.RowsCount);

                    //Console.WriteLine(string.Format(
                    //    "orign1:[StartColIndex-{4},InsertCount-{0},groupColumnCount-{1},StartRowIndex-{2},RowCount{3},tplLastColumnIndex{5}]",
                    //    InsertCount, groupColumnCount, block.StartRowIndex, block.RowCount, StartCellIndex, tplLastColumnIndex));

                    RangeHelper.InsertCopyRange(TplRange.Worksheet, range,
                                                StartColIndex + InsertCount, block.StartParseRowIndex,
                                                GroupColumnCount, block.RowsCount,
                                                InsertRangeDirection.Right,
                                                TplLastColumnIndex);
                }
                var orign = RangeHelper.GetRange(TplRange.Worksheet, (StartColIndex + InsertCount) - GroupColumnCount,
                                                 block.TplRange.Row, GroupColumnCount, block.TplRowCount);

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

                RefreshLineTplRanges(block, GroupColumnCount);
                block.TplColumCount += GroupColumnCount;
                block.ColumnsCount  += GroupColumnCount;
            }
            for (var i = 0; i < block.TplLineList.Count; i++)
            {
                var line = block.TplLineList[i];
                for (var j = 0; j < GroupColumnCount; j++)
                {
                    var num3    = (StartCellIndex + ((InsertCount > 0) ? (InsertCount - GroupColumnCount) : 0)) + j;
                    var tplCell = line.CellList[num3];
                    if (InsertCount > 0)
                    {
                        tplCell = tplCell.Copy();
                        tplCell.LastColIndex += GroupColumnCount;
                        line.CellList.Insert(num3 + GroupColumnCount, tplCell);
                    }
                    if (tplCell.Formula != null)
                    {
                        foreach (var groupKey in tplCell.Formula.KeyList)
                        {
                            for (var searchKey = groupKey.SearchKey; searchKey != null; searchKey = searchKey.NextKey)
                            {
                                if (IsGroupedColumn(searchKey.KeyName))
                                {
                                    searchKey.KeyValue = RangeHelper.GetTableValue(dataTable, valueIndex,
                                                                                   searchKey.KeyName);
                                    searchKey.IsFixedValue = true;
                                }
                            }
                            block.GroupKeyList.Add(groupKey.Copy());
                            if (groupKey.SearchKey != null)
                            {
                                groupKey.SearchKey.FillKey(dataTable, valueIndex);
                            }
                            block.Holder.AddValue(block.CountedMap, groupKey, dataTable, valueIndex);
                        }
                    }
                    else if (tplCell.HgOption != InsertOption.Never)
                    {
                        tplCell.TplTextContent = Convert.ToString(
                            RangeHelper.GetTableValue(dataTable, valueIndex, tplCell.TplValueColName));
                    }
                    tplCell.GroupAlign = GroupAlign.None;
                    Console.WriteLine(string.Concat("Inserted hg [", i.ToString().PadLeft(3), "][",
                                                    num3.ToString().PadLeft(3), "] = ", tplCell.Formula));
                    if (i < block.RowsCount)
                    {
                        var currentCellRange = RangeHelper.GetCell(TplRange.Worksheet, (StartColIndex + InsertCount) + j,
                                                                   block.StartParseRowIndex + i);
                        tplCell.WriteCell(Tpl, holder, currentCellRange, dataTable, valueIndex);
                    }
                }
            }
            InsertCount += GroupColumnCount;
        }