Ejemplo n.º 1
0
        public int FillLine(GroupDataHolder holder, int currentRowIndex, System.Data.DataTable table, int valueRowIndex)
        {
            // Judge Dose Need New Line

            int startIndex = IsNeedNewLine(holder, currentRowIndex, table, valueRowIndex);

            if (startIndex < 0)
            {
                return(0);
            }
            if (startIndex >= 0)
            {
                // Insert New Line
                /* Range newLineRange = */
                RangeHelper.InsertCopyRange(tplRange.Worksheet, tplRange, cellList.Count, 1, colIndex, currentRowIndex, XlInsertShiftDirection.xlShiftDown);

                insertedRowList.Add(currentRowIndex);
            }


            UpdateLine(currentRowIndex, holder, startIndex, table, valueRowIndex, MergeOption.Left, false);
            UpdateLine(currentRowIndex, holder, startIndex, table, valueRowIndex, MergeOption.Up, true);

            return(1);
        }
Ejemplo n.º 2
0
        public void InsertOneColumn(TplBlock block, int colIndex, GroupDataHolder holder, DataTable table, int valueIndex, bool hasData)
        {
            if (hasData)
            {
                // block.startRowIndex ;
                Range colRange = RangeHelper.GetRange(tplRange.Worksheet,
                                                      startColIndex + colIndex, block.startRowIndex,
                                                      1, block.rowCount);
                // Insert new ;
                RangeHelper.InsertCopyRange(tplRange.Worksheet, colRange,
                                            1, block.rowCount,
                                            startColIndex + gCols + insertCount, block.startRowIndex,
                                            XlInsertShiftDirection.xlShiftToRight, tplLastColCount);
            }
            // Insert new Col in Template.
            Range tplColRange = RangeHelper.GetRange(tplRange.Worksheet,
                                                     startColIndex + colIndex, block.tplRange.Row,
                                                     1, block.tplRowCount);

            RangeHelper.InsertCopyRange(tplRange.Worksheet, tplColRange,
                                        1, block.tplRowCount,
                                        startColIndex + gCols + insertCount, tplColRange.Row,
                                        XlInsertShiftDirection.xlShiftToRight, tplLastColCount);
            // Refresh Line.TplRange ;
            RefreshLineTplRanges(block, 1);

            block.tplColumCount += 1;
            block.colCount      += 1;

            // Insert cell into exsit lineList.
            for (int lineIndex = 0; lineIndex < block.lineList.Count; lineIndex++)
            {
                TplLine line = block.lineList[lineIndex];

                int cellIndex = startCellIndex + colIndex;

                TplCell cell0 = line.cellList[cellIndex];

                TplCell cell = cell0.Copy();
                cell.lastColIndex += 1;


                line.cellList.Insert(startCellIndex + gCols + insertCount, cell);

                /*
                 * if (cell.useExcelFormula)
                 * {
                 *      cell.tplRange = cell0.tplRange ;
                 * }
                 */
                if (cell.formula != null)
                {
                    for (int keyIndex = 0; keyIndex < cell.formula.keyList.Count; keyIndex++)
                    {
                        GroupValueSearchKey gkey = cell.formula.keyList[keyIndex];
                        if (gkey.rKey == null)
                        {
                            SearchKey key0 = new SearchKey();
                            key0.colName = gkey.valueColName;

                            gkey.rKey = ReusedKey.FindReusedKey(key0);
                        }
                        SearchKey key = gkey.key;
                        while (key != null)
                        {
                            if (IsGroupedColumn(key.colName))
                            {
                                key.keyValue     = RangeHelper.GetColValue(table, valueIndex, key.colName);
                                key.isFixedValue = true;
                            }
                            key = key.nextKey;
                        }

                        block.gkeyList.Add(gkey.Copy());
                        if (gkey.key != null)
                        {
                            gkey.key.FillKey(table, valueIndex);
                        }

                        block.holder.AddValue(block.countedMap, gkey, table, valueIndex);
                    }
                }

                /*
                 * else if (cell.hgOption != InsertOption.never)
                 * {
                 *      // set fixed text
                 *      cell.tplTextContent = Convert.ToString(RangeHelper.GetColValue (table, valueIndex, cell.tplValueColName)) ;
                 * }
                 */

                cell.align = GroupAlign.none;

                Console.WriteLine("Inserted hg Line[" + lineIndex + "]cell[" + cellIndex + "] = " + cell.formula);

                /* update Row Value */
                if (lineIndex < block.rowCount)
                {
                    Range cellRange = RangeHelper.GetCell(tplRange.Worksheet, startColIndex + gCols + insertCount,
                                                          block.startRowIndex + lineIndex);

                    cell.WriteCell(tpl, holder, cellRange, table, valueIndex);
                }
            }
            // Console.WriteLine ("---- End of " + valueIndex);
            // increment next

            nextCloIndex += 1;
            insertCount++;
        }
Ejemplo n.º 3
0
        public void InsertColumn(TplBlock block, GroupDataHolder holder, DataTable table, int valueIndex, bool hasData)
        {
            // do insert
            if (insertCount > 0)
            {
                if (hasData)
                {
                    // block.startRowIndex ;
                    Range colRange = RangeHelper.GetRange(tplRange.Worksheet,
                                                          startColIndex + insertCount - gCols, block.startRowIndex,
                                                          gCols, block.rowCount);
                    // Insert new ;
                    RangeHelper.InsertCopyRange(tplRange.Worksheet, colRange,
                                                gCols, block.rowCount,
                                                startColIndex + insertCount, block.startRowIndex,
                                                XlInsertShiftDirection.xlShiftToRight, tplLastColCount);
                }
                // Insert new Col in Template.
                Range tplColRange = RangeHelper.GetRange(tplRange.Worksheet,
                                                         startColIndex + insertCount - gCols, block.tplRange.Row,
                                                         gCols, block.tplRowCount);

                RangeHelper.InsertCopyRange(tplRange.Worksheet, tplColRange,
                                            gCols, block.tplRowCount,
                                            startColIndex + insertCount, tplColRange.Row,
                                            XlInsertShiftDirection.xlShiftToRight, tplLastColCount);
                // Refresh Line.TplRange ;
                RefreshLineTplRanges(block, gCols);

                block.tplColumCount += gCols;
                block.colCount      += gCols;
            }


            // Insert cell into exsit lineList.
            for (int lineIndex = 0; lineIndex < block.lineList.Count; lineIndex++)
            {
                TplLine line = block.lineList [lineIndex];

                for (int j = 0; j < gCols; j++)
                {
                    int cellIndex = startCellIndex + (insertCount > 0 ? (insertCount - gCols) : 0) + j;

                    TplCell cell = line.cellList [cellIndex];

                    /* if (cell.lastColIndex != nextCloIndex - (insertCount > 0 ? 1 : 0)) */
                    // if (cell.lastColIndex < nextCloIndex || cell.lastColIndex >= nextCloIndex + gCols)
                    //  continue ;

                    //	if (lineIndex == 2)
                    //		lineIndex = 2 ;

                    if (insertCount > 0)
                    {
                        cell = cell.Copy();
                        cell.lastColIndex += gCols;

                        line.cellList.Insert(cellIndex + gCols, cell);
                    }

                    if (cell.formula != null)
                    {
                        for (int keyIndex = 0; keyIndex < cell.formula.keyList.Count; keyIndex++)
                        {
                            GroupValueSearchKey gkey = cell.formula.keyList[keyIndex];
                            SearchKey           key  = gkey.key;
                            while (key != null)
                            {
                                if (IsGroupedColumn(key.colName))
                                {
                                    key.keyValue     = RangeHelper.GetColValue(table, valueIndex, key.colName);
                                    key.isFixedValue = true;
                                }
                                key = key.nextKey;
                            }

                            block.gkeyList.Add(gkey.Copy());
                            if (gkey.key != null)
                            {
                                gkey.key.FillKey(table, valueIndex);
                            }

                            block.holder.AddValue(block.countedMap, gkey, table, valueIndex);
                        }
                    }
                    else
                    if (cell.hgOption != InsertOption.never)
                    {
                        cell.tplTextContent = Convert.ToString(cell.GetValueByIndex(valueIndex, table));
                    }

                    cell.align = GroupAlign.none;

                    Console.WriteLine("Inserted hg Line[" + lineIndex + "]cell[" + cellIndex + "] = " + cell.formula);

                    /* update Row Value */
                    if (lineIndex < block.rowCount)
                    {
                        Range cellRange = RangeHelper.GetCell(tplRange.Worksheet, startColIndex + (insertCount /* == 0 ? 0 : insertCount - 1*/) + j,
                                                              block.startRowIndex + lineIndex);

                        cell.WriteCell(tpl, holder, cellRange, table, valueIndex);
                    }
                }
            }
            // Console.WriteLine ("---- End of " + valueIndex);
            // increment next

            nextCloIndex += gCols;
            insertCount  += gCols;
        }
Ejemplo n.º 4
0
        public void FillTemplate()
        {
            for (int i = 0; i < blockList.Count; i++)
            {
                TplBlock block = blockList [i];

                if (block.copyOnly)
                {
                    Range range = RangeHelper.InsertCopyRange(sheet, block.tplRange,
                                                              block.tplColumCount, block.tplRowCount,
                                                              block.startColIndex, startRowIndex + rowCount,
                                                              XlInsertShiftDirection.xlShiftDown);

                    IEnumerator e = RangeHelper.GetRangeCells(range);

                    while (e.MoveNext())
                    {
                        Range cell = (Range)e.Current;

                        if (cell.HasMerged)
                        {
                            continue;
                        }

                        string s = cell.Value2 as string;

                        if (s != null && s.StartsWith("#") && s.Length > 1 &&
                            paramMap != null)
                        {
                            s = s.Substring(1);
                            string[] s2 = s.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);


                            object pValue = null;
                            paramMap.TryGetValue(s2 [0], out pValue);
                            string format = "";
                            if (s2.Length > 1)
                            {
                                format = s2 [1].ToLower();
                            }
                            RangeHelper.UpdateCellValue(this, cell, pValue, format);
                        }

                        CellRange origin = RangeHelper.GetRange(sheet, cell.Column, cell.Row - startRowIndex - rowCount + block.startRowIndex, 1, 1);
                        if (origin.HasMerged)
                        {
                            // doMerge
                            int col     = origin.MergeArea.Column;
                            int mWidth  = origin.MergeArea.ColumnCount;
                            int row     = origin.MergeArea.Row + startRowIndex + rowCount - block.startRowIndex;
                            int mHeight = origin.MergeArea.RowCount;

                            CellRange mRange = RangeHelper.GetRange(sheet, col, row, mWidth, mHeight);
                            if (!mRange.HasMerged)
                            {
                                mRange.Merge();
                            }
                        }
                    }

                    rowCount += block.tplRowCount;
                }
                else
                {
                    block.startRowIndex = startRowIndex + rowCount;

                    if (block.isChart)
                    {
                        // chart block should be filled at last.
                        return;
                    }

                    // check cloumn table first
                    if (!string.IsNullOrEmpty(block.tplColTableName) &&
                        dset.Tables.Contains(block.tplColTableName))
                    {
                        block.CreateDColumns(dset.Tables [block.tplColTableName]);
                    }

                    if (!dset.Tables.Contains(block.tableName))
                    {
                        throw new ArgumentException("DataTable [" + block.tableName + "] of Block [" + block.name + "] not found in DataSet!");
                    }


                    if (dset.Tables[block.tableName].Rows.Count <= 0 && block.emptyTableName != null)
                    {
                        rowCount += block.FillBlock(dset.Tables[block.emptyTableName]);
                    }
                    else
                    {
                        rowCount += block.FillBlock(dset.Tables [block.tableName]);
                    }
                }
            }
        }