DEV Community

AsposeCells
AsposeCells

Posted on • Edited on

Copy Excel Range to Worksheet in C#.NET

Microsoft Excel Range can contain a single cell or multiple cells. It has a start cell and end cell. All the cells that lie within start cell and end cell constitutes a range. Sometimes, user wants to copy a range of cells to some other location inside the same worksheet or to some other location inside the different worksheet.

The purpose of this article is to explain how the C# developers or programmers can use Aspose.Cells for .NET in their applications to copy Excel range to same worksheet or different worksheet.

Aspose.Cells API supports all .NET frameworks e.g. .NET 2.0, .NET 3.5, .NET 4.0, .NET 7.0, .NET Core, .NET Standard 2.0, Xamarin and can be used to develop both ASP.NET web sites and Windows Forms application. It is also available in other platforms e.g. Java, C++, Android, JavaScript, PHP etc. Besides, Aspose.Cells is available in Cloud as REST or RESTful APIs.

Copy Excel Range to Same Worksheet

The following C# sample code loads the sample Excel file inside the Aspose.Cells Workbook object. It then accesses the first worksheet which contains the source Excel range that we want to copy to same worksheet. It then uses the Range.Copy() method to copy it to new location inside the worksheet.

The following screenshot shows the sample Excel file used inside the code and the output Excel file generated by the code for your reference. As you can see inside the screenshot, the source Excel range has been copied to the destination Excel range.

Caption: Excel Range copied to different location inside the Same Worksheet using Aspose.Cells API

Excel Range copied to different location inside the Same Worksheet using Aspose.Cells API

Copy Excel Range to Different Worksheet

The following C# sample code loads the sample Excel file inside the Aspose.Cells Workbook object. It accesses the first worksheet which contains the source Excel range and the second worksheet where source range is to be copied. It then copies source range of first worksheet into destination range inside second worksheet using the Range.Copy() method.

The following screenshot shows the sample Excel file used inside the code and the output Excel file generated by the code for your reference. As you can see inside the screenshot, the source Excel range has been copied to the destination Excel range in different worksheet.

Caption: Excel Range copied to Different Worksheet using Aspose.Cells API

Excel Range copied to Different Worksheet using Aspose.Cells API

See also

Top comments (1)

Collapse
 
rupam___bd profile image
Jark Berg

zetexcel.com has made my problems solved. They develop high performance applications to Create, Edit, Convert or Print Excel spreadsheet file formats without requiring Microsoft Excel.