SpreadsheetGear 2017
Copy(IRange) Method
Example 






SpreadsheetGear Namespace > IRange Interface > Copy Method : Copy(IRange) Method
The destination range.
Copies the cells, rows and/or columns of the current IRange to the destination IRange.
Syntax
'Declaration
 
Overloads Sub Copy( _
   ByVal destination As IRange _
) 
'Usage
 
Dim instance As IRange
Dim destination As IRange
 
instance.Copy(destination)
void Copy( 
   IRange destination
)
procedure Copy( 
    destination: IRange
); 
function Copy( 
   destination : IRange
);
void Copy( 
   IRange* destination
) 
void Copy( 
   IRange^ destination
) 

Parameters

destination
The destination range.
Remarks
If the current range is not large enough to fill the destination range, the current range is repeated.
Example
using System;
 
namespace SpreadsheetGear.CopySample
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a workbook
            SpreadsheetGear.IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook();
            SpreadsheetGear.IWorksheet worksheet = workbook.Worksheets[0];
            SpreadsheetGear.IRange cells = worksheet.Cells;
 
            // Put some data in the workbook.
            cells["A2"].Value = "Corn";
            cells["A3"].Value = "Wheat";
            cells["A4"].Value = "Barley";
            cells["B1"].Value = "Jan";
            cells["C1"].Value = "Feb";
            cells["D1"].Value = "Mar";
            cells["B2:D4"].Formula = "=RAND()*10000";
 
            // Make a copy in the same workbook - the destination will be
            // automatically sized to fit the source.
            cells["A1:D4"].Copy(cells["A6"]);
 
            // Create a 2nd worksheet.
            SpreadsheetGear.IWorksheet worksheet2 = workbook.Worksheets.Add();
 
            // Copy from the first worksheet to the 2nd.
            cells["A1:D4"].Copy(worksheet2.Cells["A1"]);
 
            // Save to disk.
            workbook.SaveAs(@"c:\CopySample.xls", FileFormat.Excel8);
        }
    }
}
Imports System
Imports SpreadsheetGear
 
Namespace SpreadsheetGear.CopySample
    Class Program
        Public Overloads 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
 
            ' Put some data in the workbook.
            cells("A2").Value = "Corn"
            cells("A3").Value = "Wheat"
            cells("A4").Value = "Barley"
            cells("B1").Value = "Jan"
            cells("C1").Value = "Feb"
            cells("D1").Value = "Mar"
            cells("B2:D4").Formula = "=RAND()*10000"
 
            ' Make a copy in the same workbook - the destination will be
            ' automatically sized to fit the source.
            cells("A1:D4").Copy(cells("A6"))
 
            ' Create a 2nd worksheet.
            Dim worksheet2 As IWorksheet = workbook.Worksheets.Add()
 
            ' Copy from the first worksheet to the 2nd.
            cells("A1:D4").Copy(worksheet2.Cells("A1"))
 
            ' Save to disk.
            workbook.SaveAs("c:\CopySample.xls", FileFormat.Excel8)
        End Sub 'Main '
    End Class 'Program
End Namespace 'SpreadsheetGear.CopySample
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

IRange Interface
IRange Members
Overload List
Copy(IRange,PasteType,PasteOperation,Boolean,Boolean) Method
FillDown Method
FillLeft Method
FillRight Method
FillUp Method