public void Insert(XlInsertShiftDirection shift, XlRange copyOrigin)
 {
     object[] paramArray = new object[2];
     paramArray[0] = shift;
     paramArray[1] = copyOrigin.COMReference;
     InstanceType.InvokeMember("Insert", BindingFlags.InvokeMethod, null, ComReference, paramArray, XlLateBindingApiSettings.XlThreadCulture);
 }
Exemple #2
0
 public static Range InsertCopyRange(Worksheet sheet, Range orign, int columns, int rows, int targetColumn,
                                     int targetRow, XlInsertShiftDirection direction)
 {
     return(InsertCopyRange(sheet, orign, columns, rows, targetColumn,
                            targetRow, direction, 1));
 }
        /// <summary>在工作表或宏表中插入一个单元格或单元格区域,其他单元格相应移位以腾出空间。
        /// </summary>
        /// <param name="Shift">指定单元格的调整方式。可为以下 XlInsertShiftDirection 常量之一:xlShiftToRight 或 xlShiftDown。如果省略此参数,Microsoft Excel 将根据区域的形状确定调整方式。</param>
        /// <param name="CopyOrigin">复制的起点。</param>
        public dynamic Insert(XlInsertShiftDirection? Shift = null, object CopyOrigin = null)
        {
            _objaParameters = new object[2] {
                Shift == null ? System.Type.Missing : Shift,
                CopyOrigin == null ? System.Type.Missing : CopyOrigin
            };

            return _objRange.GetType().InvokeMember("Insert", BindingFlags.InvokeMethod, null, _objRange, _objaParameters);
        }
Exemple #4
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);
        }
Exemple #5
0
 public void Insert(XlInsertShiftDirection direction)
 {
     _worksheet.Cells[Number, 1].EntireRow.Insert(direction);
 }