Skip to content

Commit 68dc299

Browse files
988730-CopyUsedRangeSample
1 parent 1fd0c3d commit 68dc299

File tree

6 files changed

+56
-0
lines changed

6 files changed

+56
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Solution>
2+
<Project Path="CopyUsedRange/CopyUsedRange.csproj" />
3+
</Solution>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net10.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="*" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<None Update="Output\*">
16+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
17+
</None>
18+
<None Update="Data\*">
19+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
20+
</None>
21+
</ItemGroup>
22+
23+
</Project>
Binary file not shown.
Binary file not shown.

FAQ/Copy Used Range/.NET/CopyUsedRange/CopyUsedRange/Output/.gitkeep

Whitespace-only changes.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Syncfusion.XlsIO;
2+
3+
namespace CopyUsedRange
4+
{
5+
class Program
6+
{
7+
public static void Main(string[] args)
8+
{
9+
using (ExcelEngine excelEngine = new ExcelEngine())
10+
{
11+
IApplication application = excelEngine.Excel;
12+
application.DefaultVersion = ExcelVersion.Xlsx;
13+
IWorkbook sourceWorkbook = excelEngine.Excel.Workbooks.Open(Path.GetFullPath(@"Data/Source.xlsx"));
14+
IWorkbook destinationWorkbook = excelEngine.Excel.Workbooks.Open(Path.GetFullPath(@"Data/Destination.xlsx"));
15+
16+
IWorksheet sourceWorksheet = sourceWorkbook.Worksheets["Sheet1"];
17+
IWorksheet destinationWorksheet = destinationWorkbook.Worksheets["Sheet1"];
18+
19+
//Get the actual used range from source sheet
20+
IRange sourceRange = sourceWorksheet.UsedRange;
21+
22+
//Copy the entire used range from source sheet to destination sheet
23+
sourceRange.CopyTo(destinationWorksheet.Range[sourceRange.Row, sourceRange.Column]);
24+
25+
//Save the destination workbook
26+
destinationWorkbook.SaveAs(Path.GetFullPath(@"../../../Output/Output.xlsx"));
27+
}
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)