File tree Expand file tree Collapse file tree
FAQ/Last row of worksheet/.NET/LastRowOfWorksheet Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <Solution >
2+ <Project Path =" LastRowOfWorksheet/LastRowOfWorksheet.csproj" />
3+ </Solution >
Original file line number Diff line number Diff line change 1+ <Project Sdk =" Microsoft.NET.Sdk" >
2+
3+ <PropertyGroup >
4+ <OutputType >Exe</OutputType >
5+ <TargetFramework >net9.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 >
Original file line number Diff line number Diff line change 1+ using Syncfusion . XlsIO ;
2+
3+ namespace LastRowOfWorksheet
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 workbook = application . Workbooks . Open ( Path . GetFullPath ( @"Data/Input.xlsx" ) ) ;
14+ IWorksheet worksheet = workbook . Worksheets [ 0 ] ;
15+
16+ //Get the last row from the used range
17+ int lastrow = workbook . ActiveSheet . UsedRange . LastRow ;
18+
19+ //Display the last row
20+ Console . WriteLine ( "The last row in the used range is: " + lastrow ) ;
21+
22+ //Saving the workbook
23+ workbook . SaveAs ( Path . GetFullPath ( @"Output/Output.xlsx" ) ) ;
24+ }
25+ }
26+ }
27+ }
You can’t perform that action at this time.
0 commit comments