From 6fa5f2993371fcdb6fc6c56883b8d28842093589 Mon Sep 17 00:00:00 2001 From: KarthikaSF4773 Date: Wed, 17 Dec 2025 12:52:35 +0530 Subject: [PATCH 1/2] 991263-FirstUsedCellUG --- ...in-the-used-range-in-an-Excel-worksheet.md | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 Document-Processing/Excel/Excel-Library/NET/faqs/how-to-retrieve-the-first-cell-in-the-used-range-in-an-Excel-worksheet.md diff --git a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-retrieve-the-first-cell-in-the-used-range-in-an-Excel-worksheet.md b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-retrieve-the-first-cell-in-the-used-range-in-an-Excel-worksheet.md new file mode 100644 index 000000000..34a06dc90 --- /dev/null +++ b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-retrieve-the-first-cell-in-the-used-range-in-an-Excel-worksheet.md @@ -0,0 +1,89 @@ +--- +title: Retrieve the first cell in the used range in an Excel worksheet | Syncfusion +description: Code example to retrieve the first cell in the used range in an Excel worksheet using Syncfusion .NET Excel library (XlsIO). +platform: document-processing +control: XlsIO +documentation: UG +--- + +# How to retrieve the first cell in the used range in an Excel worksheet? + +The following code examples demonstrate retrieving the first cell in the used range of an Excel worksheet using C# (Cross-platform and Windows-specific) and VB.NET. + +{% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/FAQ/First%20used%20cell%20in%20used%20range/.NET/FirstUsedCellInUsedRange/FirstUsedCellInUsedRange/Program.cs,180" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Input.xlsx")); + IWorksheet worksheet = workbook.Worksheets[0]; + + //Get the used range of the worksheet + IRange usedRange = worksheet.UsedRange; + + //Get the first cell from the used range + IRange firstCell = worksheet.Range[usedRange.Row, usedRange.Column]; + + //Get the address of the first cell + string firstCellAddress = firstCell.AddressLocal; + + //Display the address of the first cell + Console.WriteLine("The address of the first used cell in used range is: " + firstCellAddress); + + //Save the workbook + workbook.SaveAs(Path.GetFullPath(@"Output/Output.xlsx")); +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Open("Input.xlsx"); + IWorksheet worksheet = workbook.Worksheets[0]; + + //Get the used range of the worksheet + IRange usedRange = worksheet.UsedRange; + + //Get the first cell from the used range + IRange firstCell = worksheet.Range[usedRange.Row, usedRange.Column]; + + //Get the address of the first cell + string firstCellAddress = firstCell.AddressLocal; + + //Display the address of the first cell + Console.WriteLine("The address of the first used cell in used range is: " + firstCellAddress); + + //Save the workbook + workbook.SaveAs("Output.xlsx"); +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Using excelEngine As New ExcelEngine() + Dim application As IApplication = excelEngine.Excel + application.DefaultVersion = ExcelVersion.Xlsx + Dim workbook As IWorkbook = application.Workbooks.Open("Input.xlsx") + Dim worksheet As IWorksheet = workbook.Worksheets(0) + + 'Get the used range of the worksheet + Dim usedRange As IRange = worksheet.UsedRange + + 'Get the first cell from the used range + Dim firstCell As IRange = worksheet.Range(usedRange.Row, usedRange.Column) + + 'Get the address of the first cell + Dim firstCellAddress As String = firstCell.AddressLocal + + 'Display the address of the first cell + Console.WriteLine("The address of the first used cell in used range is: " & firstCellAddress) + + 'Save the workbook + workbook.SaveAs("Output.xlsx") +End Using +{% endhighlight %} +{% endtabs %} + +A complete working example in C# is present on this GitHub page. \ No newline at end of file From d24af6af7be0b42e0dbffabc7f3f0b45ebf3cd39 Mon Sep 17 00:00:00 2001 From: KarthikaSF4773 Date: Wed, 17 Dec 2025 13:50:32 +0530 Subject: [PATCH 2/2] 991263-FirstUsedCellUG --- ...-to-retrieve-the-first-cell-in-the-used-range-in-Excel.md} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename Document-Processing/Excel/Excel-Library/NET/faqs/{how-to-retrieve-the-first-cell-in-the-used-range-in-an-Excel-worksheet.md => how-to-retrieve-the-first-cell-in-the-used-range-in-Excel.md} (95%) diff --git a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-retrieve-the-first-cell-in-the-used-range-in-an-Excel-worksheet.md b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-retrieve-the-first-cell-in-the-used-range-in-Excel.md similarity index 95% rename from Document-Processing/Excel/Excel-Library/NET/faqs/how-to-retrieve-the-first-cell-in-the-used-range-in-an-Excel-worksheet.md rename to Document-Processing/Excel/Excel-Library/NET/faqs/how-to-retrieve-the-first-cell-in-the-used-range-in-Excel.md index 34a06dc90..1315eb382 100644 --- a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-retrieve-the-first-cell-in-the-used-range-in-an-Excel-worksheet.md +++ b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-retrieve-the-first-cell-in-the-used-range-in-Excel.md @@ -1,12 +1,12 @@ --- -title: Retrieve the first cell in the used range in an Excel worksheet | Syncfusion +title: Retrieve the first cell in the used range in Excel | Syncfusion description: Code example to retrieve the first cell in the used range in an Excel worksheet using Syncfusion .NET Excel library (XlsIO). platform: document-processing control: XlsIO documentation: UG --- -# How to retrieve the first cell in the used range in an Excel worksheet? +# How to retrieve the first cell in the used range in Excel? The following code examples demonstrate retrieving the first cell in the used range of an Excel worksheet using C# (Cross-platform and Windows-specific) and VB.NET.