Skip to content
Merged
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/Last Row/.NET/Last Row/Last Row.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Solution>
<Project Path="Last Row/Last Row.csproj" />
</Solution>
21 changes: 21 additions & 0 deletions FAQ/Last Row/.NET/Last Row/Last Row/Last Row.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Last_Row</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

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

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

</Project>
Empty file.
45 changes: 45 additions & 0 deletions FAQ/Last Row/.NET/Last Row/Last Row/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Syncfusion.XlsIO;
using Syncfusion.XlsIO.Implementation;
using Syncfusion.XlsIO.Implementation.Collections;

class Program
{
static void Main(string[] args)
{
// Create an instance of ExcelEngine
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Create(1);

IWorksheet sheet = workbook.Worksheets[0];
sheet["A1:B10"].Text = "10";
sheet["C1:C5"].Text = "20";

int lastRow = GetLastRow(3, sheet as WorksheetImpl);
Console.WriteLine("Last Row in Column C: " + lastRow);

workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
}
}

private static int GetLastRow(int column, WorksheetImpl worksheet)
{
int firstRow = worksheet.UsedRange.Row;
int lastRow = worksheet.UsedRange.LastRow;
for (int iRow = lastRow; iRow >= firstRow; iRow--)
{
RowStorage rowStorage = WorksheetHelper.GetOrCreateRow(worksheet, iRow - 1, false);
if (rowStorage != null)
{
RowStorageEnumerator enumerator = rowStorage.GetEnumerator(worksheet.RecordExtractor) as RowStorageEnumerator;
while (enumerator.MoveNext())
{
if (enumerator.ColumnIndex + 1 == column)
return iRow;
}
}
}
return -1;
}
}
Loading