Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions FAQ/Copy Used Range/.NET/CopyUsedRange/CopyUsedRange.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Solution>
<Project Path="CopyUsedRange/CopyUsedRange.csproj" />
</Solution>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="*" />
</ItemGroup>

<ItemGroup>
<None Update="Output\*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Data\*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Binary file not shown.
Binary file not shown.
Empty file.
30 changes: 30 additions & 0 deletions FAQ/Copy Used Range/.NET/CopyUsedRange/CopyUsedRange/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Syncfusion.XlsIO;

namespace CopyUsedRange
{
class Program
{
public static void Main(string[] args)
{
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook sourceWorkbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Source.xlsx"));
IWorkbook destinationWorkbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Destination.xlsx"));

IWorksheet sourceWorksheet = sourceWorkbook.Worksheets["Sheet1"];
IWorksheet destinationWorksheet = destinationWorkbook.Worksheets["Sheet1"];

//Get the actual used range from source sheet
IRange sourceRange = sourceWorksheet.UsedRange;

//Copy the entire used range from source sheet to destination sheet
sourceRange.CopyTo(destinationWorksheet.Range[sourceRange.Row, sourceRange.Column]);

//Save the destination workbook
destinationWorkbook.SaveAs(Path.GetFullPath(@"Output/Output.xlsx"));
}
}
}
}