See Also

IRange Interface  | IRange Members  | Overload List  | Delete Method  | Delete(DeleteShiftDirection) Method  | Insert Method  | InsertShiftDirection Enumeration

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Language

Visual Basic

C#

C++

C++/CLI

Show All

shiftDirection
Specifies whether to shift cells right or down.
See Also Languages SpreadsheetGear The Performance Spreadsheet Component Company 

Insert(InsertShiftDirection) Method

SpreadsheetGear Namespace > IRange Interface > Insert Method : Insert(InsertShiftDirection) Method

Inserts cells, rows or columns by shifting cells right or down and fixing up formulas and formats.

[Visual Basic]
Overloads Overridable Sub Insert( _    ByVal shiftDirection As InsertShiftDirection _ )
[C#]
virtual void Insert(    InsertShiftDirection shiftDirection );
[C++]
virtual void Insert(    InsertShiftDirection shiftDirection )
[C++/CLI]
virtual void Insert(    InsertShiftDirection shiftDirection )

Parameters

shiftDirection
Specifies whether to shift cells right or down.

Example

[C#] 

using System; 
using SpreadsheetGear; 
using System.Diagnostics; 
 
namespace SpreadsheetGear.InsertExample 

    class Program 
    { 
        static void Main() 
        { 
            // Create a workbook. 
            IWorkbook workbook = Factory.GetWorkbook(); 
            IWorksheet worksheet = workbook.Worksheets[0]; 
            IRange cells = worksheet.Cells; 
 
            // Set some text in A1:B2. 
            cells["A1"].Formula = "A1"; 
            cells["A2"].Formula = "A2"; 
            cells["B1"].Formula = "B1"; 
            cells["B2"].Formula = "B2"; 
 
            // Insert two rows before row 2. 
            cells["2:3"].Insert(); 
 
            // Insert three columns before column 'B'. 
            cells["B:D"].Insert(); 
 
            // Verify new locations - A1 has not moved. 
            Debug.Assert(cells["A1"].Formula.Equals("A1")); 
            // A2 has been moved down two rows. 
            Debug.Assert(cells["A4"].Formula.Equals("A2")); 
            // B1 has been moved right three columns. 
            Debug.Assert(cells["E1"].Formula.Equals("B1")); 
            // B2 has been moved down two rows and right three columns. 
            Debug.Assert(cells["E4"].Formula.Equals("B2")); 
 
            // Insert one cell before E4 shifting E4 down to E5. 
            cells["E4"].Insert(InsertShiftDirection.Down); 
            Debug.Assert(cells["E5"].Formula.Equals("B2")); 
 
            // Insert one cell before E5 shifting E5 right to F5. 
            cells["E5"].Insert(InsertShiftDirection.Right); 
            Debug.Assert(cells["F5"].Formula.Equals("B2")); 
        } 
    } 

    

[Visual Basic] 

Imports System
Imports SpreadsheetGear
Imports System.Diagnostics


Namespace SpreadsheetGear.InsertExample

    Class Program

        Shared Sub Main()
            ' Create a workbook.
            Dim workbook As IWorkbook = Factory.GetWorkbook()
            Dim worksheet As IWorksheet = workbook.Worksheets(0)
            Dim cells As IRange = worksheet.Cells

            ' Set some text in A1:B2.
            cells("A1").Formula = "A1"
            cells("A2").Formula = "A2"
            cells("B1").Formula = "B1"
            cells("B2").Formula = "B2"

            ' Insert two rows before row 2.
            cells("2:3").Insert()

            ' Insert three columns before column 'B'.
            cells("B:D").Insert()

            ' Verify new locations - A1 has not moved.
            Debug.Assert(cells("A1").Formula.Equals("A1"))
            ' A2 has been moved down two rows.
            Debug.Assert(cells("A4").Formula.Equals("A2"))
            ' B1 has been moved right three columns.
            Debug.Assert(cells("E1").Formula.Equals("B1"))
            ' B2 has been moved down two rows and right three columns.
            Debug.Assert(cells("E4").Formula.Equals("B2"))

            ' Insert one cell before E4 shifting E4 down to E5.
            cells("E4").Insert(InsertShiftDirection.Down)
            Debug.Assert(cells("E5").Formula.Equals("B2"))

            ' Insert one cell before E5 shifting E5 right to F5.
            cells("E5").Insert(InsertShiftDirection.Right)
            Debug.Assert(cells("F5").Formula.Equals("B2"))
        End Sub 'Main
    End Class 'Program
End Namespace 'SpreadsheetGear.InsertExample

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

IRange Interface  | IRange Members  | Overload List  | Delete Method  | Delete(DeleteShiftDirection) Method  | Insert Method  | InsertShiftDirection Enumeration

 

 


See our live Excel Reporting, Excel Charting, Excel to DataGrid and Excel Calculation Samples.

Copyright © 2003-2007 SpreadsheetGear LLC. All Rights Reserved.

SpreadsheetGear and Spreadsheet Gear are trademarks of SpreadsheetGear LLC.