Skip to content

Commit 8a734d2

Browse files
authored
Merge pull request #178 from SyncfusionExamples/261772-GetWorksheetNames
261772-How to get the list of worksheet names in an Excel workbook using XlsIO?
2 parents ae35238 + 083cd3b commit 8a734d2

File tree

15 files changed

+343
-0
lines changed

15 files changed

+343
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35506.116 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "All Worksheet Names", "All Worksheet Names\All Worksheet Names.csproj", "{57ADBD15-12EB-458B-9AAC-BFA5C466C637}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{57ADBD15-12EB-458B-9AAC-BFA5C466C637}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{57ADBD15-12EB-458B-9AAC-BFA5C466C637}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{57ADBD15-12EB-458B-9AAC-BFA5C466C637}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{57ADBD15-12EB-458B-9AAC-BFA5C466C637}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>All_Worksheet_Names</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
</Project>
Binary file not shown.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.IO;
3+
using Syncfusion.XlsIO;
4+
using Syncfusion.XlsIO.Implementation.Collections;
5+
6+
namespace All_Worksheet_Names
7+
{
8+
class Program
9+
{
10+
static void Main(string[] args)
11+
{
12+
using (ExcelEngine excelEngine = new ExcelEngine())
13+
{
14+
IApplication application = excelEngine.Excel;
15+
application.DefaultVersion = ExcelVersion.Xlsx;
16+
17+
FileStream inputStream = new FileStream("Data/Input.xlsx", FileMode.Open, FileAccess.Read);
18+
IWorkbook workbook = application.Workbooks.Open(inputStream);
19+
20+
//Get the worksheets collection
21+
WorksheetsCollection worksheets = workbook.Worksheets as WorksheetsCollection;
22+
23+
//Print all worksheet names
24+
foreach (IWorksheet worksheet in worksheets)
25+
{
26+
Console.WriteLine(worksheet.Name);
27+
}
28+
29+
//Dispose streams
30+
inputStream.Dispose();
31+
}
32+
}
33+
}
34+
}
35+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Retrieve All Worksheet Names
2+
3+
Step 1: Create a New C# Console Application Project.
4+
5+
Step 2: Name the Project.
6+
7+
Step 3: Install the [Syncfusion.XlsIO.Net.Core](https://www.nuget.org/packages/Syncfusion.XlsIO.Net.Core) NuGet package as reference to your .NET Standard applications from [NuGet.org](https://www.nuget.org).
8+
9+
Step 4: Include the following namespaces in the **Program.cs** file.
10+
11+
```csharp
12+
using System;
13+
using System.IO;
14+
using Syncfusion.XlsIO;
15+
using Syncfusion.XlsIO.Implementation.Collections;
16+
```
17+
18+
Step 5: Include the below code snippet in **Program.cs** to retrieve all worksheet names.
19+
20+
```csharp
21+
using (ExcelEngine excelEngine = new ExcelEngine())
22+
{
23+
IApplication application = excelEngine.Excel;
24+
application.DefaultVersion = ExcelVersion.Xlsx;
25+
26+
FileStream inputStream = new FileStream("Data/Input.xlsx", FileMode.Open, FileAccess.Read);
27+
IWorkbook workbook = application.Workbooks.Open(inputStream);
28+
29+
//Get the worksheets collection
30+
WorksheetsCollection worksheets = workbook.Worksheets as WorksheetsCollection;
31+
32+
//Print all worksheet names
33+
foreach (IWorksheet worksheet in worksheets)
34+
{
35+
Console.WriteLine(worksheet.Name);
36+
}
37+
38+
//Dispose streams
39+
inputStream.Dispose();
40+
}
41+
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35506.116 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hidden Worksheet Names", "Hidden Worksheet Names\Hidden Worksheet Names.csproj", "{CEC54C9C-8AFF-4F98-8FC6-0FEF7E0AFE5A}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{CEC54C9C-8AFF-4F98-8FC6-0FEF7E0AFE5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{CEC54C9C-8AFF-4F98-8FC6-0FEF7E0AFE5A}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{CEC54C9C-8AFF-4F98-8FC6-0FEF7E0AFE5A}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{CEC54C9C-8AFF-4F98-8FC6-0FEF7E0AFE5A}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Binary file not shown.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Hidden_Worksheet_Names</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.IO;
3+
using Syncfusion.XlsIO;
4+
using Syncfusion.XlsIO.Implementation.Collections;
5+
6+
namespace Hidden_Worksheet_Names
7+
{
8+
class Program
9+
{
10+
static void Main(string[] args)
11+
{
12+
using (ExcelEngine excelEngine = new ExcelEngine())
13+
{
14+
IApplication application = excelEngine.Excel;
15+
application.DefaultVersion = ExcelVersion.Xlsx;
16+
17+
FileStream inputStream = new FileStream("Data/Input.xlsx", FileMode.Open, FileAccess.Read);
18+
IWorkbook workbook = application.Workbooks.Open(inputStream);
19+
20+
//Get the worksheets collection
21+
WorksheetsCollection worksheets = workbook.Worksheets as WorksheetsCollection;
22+
23+
//Print hidden worksheet names
24+
foreach (IWorksheet worksheet in worksheets)
25+
{
26+
if (worksheet.Visibility == WorksheetVisibility.Hidden)
27+
Console.WriteLine(worksheet.Name);
28+
}
29+
30+
//Dispose streams
31+
inputStream.Dispose();
32+
33+
}
34+
}
35+
}
36+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Retrieve Hidden Worksheet Names
2+
3+
Step 1: Create a New C# Console Application Project.
4+
5+
Step 2: Name the Project.
6+
7+
Step 3: Install the [Syncfusion.XlsIO.Net.Core](https://www.nuget.org/packages/Syncfusion.XlsIO.Net.Core) NuGet package as reference to your .NET Standard applications from [NuGet.org](https://www.nuget.org).
8+
9+
Step 4: Include the following namespaces in the **Program.cs** file.
10+
11+
```csharp
12+
using System;
13+
using System.IO;
14+
using Syncfusion.XlsIO;
15+
using Syncfusion.XlsIO.Implementation.Collections;
16+
```
17+
18+
Step 5: Include the below code snippet in **Program.cs** to retrieve hidden worksheet names.
19+
20+
```csharp
21+
using (ExcelEngine excelEngine = new ExcelEngine())
22+
{
23+
IApplication application = excelEngine.Excel;
24+
application.DefaultVersion = ExcelVersion.Xlsx;
25+
26+
FileStream inputStream = new FileStream("Data/Input.xlsx", FileMode.Open, FileAccess.Read);
27+
IWorkbook workbook = application.Workbooks.Open(inputStream);
28+
29+
//Get the worksheets collection
30+
WorksheetsCollection worksheets = workbook.Worksheets as WorksheetsCollection;
31+
32+
//Print hidden worksheet names
33+
foreach (IWorksheet worksheet in worksheets)
34+
{
35+
if (worksheet.Visibility == WorksheetVisibility.Hidden)
36+
Console.WriteLine(worksheet.Name);
37+
}
38+
39+
//Dispose streams
40+
inputStream.Dispose();
41+
42+
}
43+
```

0 commit comments

Comments
 (0)