Example #1
0
        public int CreateDColumns(DataTable table)
        {
            if (dColumn == null)
            {
                return(0);
            }

            // Current colCount include gCols, so substract it.
            colCount -= dColumn.gCols;

            // try to insert dColumns into Template.
            // dColumn.CheckColumn ()
            if (table == null || table.Rows.Count <= 0)
            {
                return(0);
            }

            for (int i = 0; i < table.Rows.Count; i++)
            {
                dColumn.CheckEachColumn(this, holder, 0, table, i);
                // dColumn.InsertColumn (this, holder, table, i, false);
            }

            dCloumnsCreated = true;

            // remove data from template
            // Insert new Col in Template.
            Range tplColRange = RangeHelper.GetRange(tplRange.Worksheet,
                                                     dColumn.startColIndex + dColumn.gCols, tplRange.Row,
                                                     tplColumCount - dColumn.startCellIndex - dColumn.gCols - 1,
                                                     // 50,
                                                     tplRowCount);

            tplColRange.Copy(
                RangeHelper.GetRange(tplRange.Worksheet,
                                     dColumn.startColIndex, tplRange.Row,
                                     tplColumCount - dColumn.startCellIndex - dColumn.gCols - 1,
                                     // 50,
                                     tplRowCount), true, true);

            /*
             * RangeHelper.InsertCopyRange(tplRange.Worksheet, tplColRange,
             *                                                      tplColumCount - dColumn.startCellIndex - dColumn.gCols,
             *                          tplRowCount,
             *                                                      startColIndex , tplColRange.Row,
             *                                                      XlInsertShiftDirection.xlShiftToRight, tplColumCount);
             */
            tplColumCount -= dColumn.gCols;
            for (int i = 0; i < lineList.Count; i++)
            {
                TplLine line = lineList [i];

                line.cellList.RemoveRange(dColumn.startCellIndex, dColumn.gCols);
                line.tplCellCount -= dColumn.gCols;
                line.tplRange      = RangeHelper.GetRange(tplRange.Worksheet,
                                                          3, line.tplRange.Row,
                                                          tplColumCount, 1);
            }
            // Refresh Line.TplRange ;
            // RefreshLineTplRanges(block, 1);

            return(1);
        }
Example #2
0
        public static Range InsertCopyRange(Worksheet sheet, Range orign, int columns, int rows, int targetColumn,
                                            int targetRow, XlInsertShiftDirection direction,
                                            int lastColCount)
        {
            insertCopyRangeCallTimes++;
            // return GetRange(sheet, targetColumn, targetRow, columns, rows);
            int orgColumn = orign.Column;
            int orgRow    = orign.Row;

            Range target = GetRange(sheet, targetColumn, targetRow, columns, rows);

            if (direction == XlInsertShiftDirection.xlShiftToRight)
            {
                // insert blank
                // target.Insert (direction, Missing.Value) ;
                // Move target from origin to Right first

                Range movedRange     = GetRange(sheet, targetColumn, targetRow, lastColCount, rows);
                Range movedNextRange = GetRange(sheet, targetColumn + columns, targetRow, lastColCount, rows);
                movedRange.Move(movedNextRange, true, false);

                target = GetRange(sheet, targetColumn, targetRow, columns, rows);
                target.UnMerge();
            }
            orign.Copy(target, false, true);

            switch (direction)
            {
            case XlInsertShiftDirection.xlShiftDown:
                // copy row height ;
                for (int i = 0; i < rows; i++)
                {
                    Range sRow = GetEntireRow(sheet, i + orgRow);
                    Range tRow = GetEntireRow(sheet, i + targetRow);
                    try
                    {
                        tRow.RowHeight = sRow.RowHeight;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Set RowHeight Error: " + e);
                    }
                }
                break;

            case XlInsertShiftDirection.xlShiftToRight:
                // copy col width ;
                for (int i = 0; i < columns; i++)
                {
                    Range sCol = GetEntireCol(sheet, i + orgColumn);
                    Range tCol = GetEntireCol(sheet, i + targetColumn + 1);

                    try
                    {
                        tCol.ColumnWidth = sCol.ColumnWidth;
                    }catch (Exception e)
                    {
                        Console.WriteLine("Set ColumnWidth Error: " + e);
                    }
                }
                break;
            }


            return(target);
        }