Skip to content

Commit 5a4c447

Browse files
authored
Merge pull request #2105 from syncfusion-content/1001194-NamedRangeUG
UG documentation 1001194: FAQ for how to retrieve the list of named ranges in an Excel workbook.
2 parents 6417813 + 03a3379 commit 5a4c447

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

Document-Processing-toc.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6150,6 +6150,9 @@
61506150
<li>
61516151
<a href="/document-processing/excel/excel-library/net/faqs/how-to-resolve-the-cannot-open-Pivot-table-source-file-error">How to resolve the cannot open pivot table source file error?</a>
61526152
</li>
6153+
<li>
6154+
<a href="/document-processing/excel/excel-library/net/faqs/how-to-retrieve-the-list-of-named-ranges-in-an-Excel-workbook">How to retrieve the list of named ranges in an Excel workbook?</a>
6155+
</li>
61536156
<li>
61546157
<a href="/document-processing/excel/excel-library/net/faqs/how-to-extract-embedded-OLE-files-from-an-Excel-workbook-as-streams">How to extract embedded OLE files from an Excel workbook as streams?</a>
61556158
</li>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
title: Retrieve the list of named ranges in an Excel workbook | Syncfusion
3+
description: Code example to retrieve the list of named ranges in an Excel workbook using Syncfusion .NET Excel library (XlsIO).
4+
platform: document-processing
5+
control: XlsIO
6+
documentation: UG
7+
---
8+
9+
# How to retrieve the list of named ranges in an Excel workbook?
10+
11+
The following code examples demonstrate retrieving the list of named ranges in an Excel workbook using C# (Cross-platform and Windows-specific) and VB.NET.
12+
13+
{% tabs %}
14+
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/FAQ/Named%20Range/.NET/RetrieveNamedRanges/RetrieveNamedRanges/Program.cs,180" %}
15+
using (ExcelEngine excelEngine = new ExcelEngine())
16+
{
17+
IApplication application = excelEngine.Excel;
18+
application.DefaultVersion = ExcelVersion.Xlsx;
19+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Input.xlsx"));
20+
IWorksheet worksheet = workbook.Worksheets[0];
21+
22+
//Retrieving names defined in the workbook
23+
IName[] names = new IName[workbook.Names.Count];
24+
for (int i = 0; i < workbook.Names.Count; i++)
25+
{
26+
names[i] = workbook.Names[i];
27+
Console.WriteLine(names[i].Name);
28+
}
29+
30+
//Saving the workbook
31+
workbook.SaveAs(Path.GetFullPath(@"Output/Output.xlsx"));
32+
}
33+
{% endhighlight %}
34+
35+
{% highlight c# tabtitle="C# [Windows-specific]" %}
36+
using (ExcelEngine excelEngine = new ExcelEngine())
37+
{
38+
IApplication application = excelEngine.Excel;
39+
application.DefaultVersion = ExcelVersion.Xlsx;
40+
IWorkbook workbook = application.Workbooks.Open("Input.xlsx");
41+
IWorksheet worksheet = workbook.Worksheets[0];
42+
43+
//Retrieving names defined in the workbook
44+
IName[] names = new IName[workbook.Names.Count];
45+
for (int i = 0; i < workbook.Names.Count; i++)
46+
{
47+
names[i] = workbook.Names[i];
48+
Console.WriteLine(names[i].Name);
49+
}
50+
51+
//Saving the workbook
52+
workbook.SaveAs("Output.xlsx");
53+
}
54+
{% endhighlight %}
55+
56+
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
57+
Using excelEngine As New ExcelEngine()
58+
' Instantiate the Excel application object
59+
Dim application As IApplication = excelEngine.Excel
60+
61+
' Set the default application version
62+
application.DefaultVersion = ExcelVersion.Xlsx
63+
64+
' Load the existing Excel workbook into IWorkbook
65+
Dim workbook As IWorkbook = application.Workbooks.Open("Input.xlsx")
66+
67+
' Get the first worksheet in the workbook into IWorksheet
68+
Dim worksheet As IWorksheet = workbook.Worksheets(0)
69+
70+
' Retrieving names defined in the workbook
71+
Dim names(workbook.Names.Count - 1) As IName
72+
For i As Integer = 0 To workbook.Names.Count - 1
73+
names(i) = workbook.Names(i)
74+
Console.WriteLine(names(i).Name)
75+
Next
76+
77+
' Saving the workbook
78+
workbook.SaveAs("Output.xlsx")
79+
End Using
80+
{% endhighlight %}
81+
{% endtabs %}
82+
83+
A complete working example in C# is present on <a href="https://github.com/SyncfusionExamples/XlsIO-Examples/tree/master/FAQ/Named%20Range/.NET/RetrieveNamedRanges">this GitHub page</a>.

0 commit comments

Comments
 (0)