Skip to content

Commit 1d1df6c

Browse files
authored
Merge pull request #164 from SyncfusionExamples/951831-DeleteHyperlinksXlsioExample
951831-FAQ for how to delete hyperlinks from worksheet without affecting the cell styles-Docs-Example
2 parents 3513546 + fc15fcd commit 1d1df6c

File tree

6 files changed

+118
-0
lines changed

6 files changed

+118
-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}") = "Delete Hyperlinks", "Delete Hyperlinks\Delete Hyperlinks.csproj", "{5BF46923-4F9F-4CFC-BF1A-336E40153917}"
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+
{5BF46923-4F9F-4CFC-BF1A-336E40153917}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{5BF46923-4F9F-4CFC-BF1A-336E40153917}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{5BF46923-4F9F-4CFC-BF1A-336E40153917}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{5BF46923-4F9F-4CFC-BF1A-336E40153917}.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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Delete_Hyperlinks</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+
<ItemGroup>
16+
<None Update="Output\*">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
</ItemGroup>
20+
</Project>

FAQ/Hyperlinks/.NET/Delete Hyperlinks/Delete Hyperlinks/Output/.gitkeep

Whitespace-only changes.
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;
5+
using Syncfusion.XlsIO.Implementation.Collections;
6+
7+
namespace Delete_Hyperlinks
8+
{
9+
class Program
10+
{
11+
static void Main(string[] args)
12+
{
13+
using (ExcelEngine excelEngine = new ExcelEngine())
14+
{
15+
IApplication application = excelEngine.Excel;
16+
application.DefaultVersion = ExcelVersion.Xlsx;
17+
FileStream inputStream = new FileStream("Data/InputTemplate.xlsx", FileMode.Open, FileAccess.Read);
18+
IWorkbook workbook = application.Workbooks.Open(inputStream);
19+
IWorksheet worksheet = workbook.Worksheets[0];
20+
21+
// Remove first hyperlink without affecting cell styles
22+
HyperLinksCollection hyperlink = worksheet.HyperLinks as HyperLinksCollection;
23+
hyperlink.Remove(hyperlink[0] as HyperLinkImpl);
24+
25+
//Saving the workbook as stream
26+
FileStream outputStream = new FileStream("Output/Output.xlsx", FileMode.Create, FileAccess.Write);
27+
workbook.SaveAs(outputStream);
28+
workbook.Close();
29+
excelEngine.Dispose();
30+
}
31+
}
32+
33+
}
34+
}
35+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# How to delete hyperlinks from worksheet without affecting the cell styles?
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;
16+
using Syncfusion.XlsIO.Implementation.Collections;
17+
```
18+
19+
Step 5: Include the below code snippet in **Program.cs** to delete hyperlinks from worksheet without affecting the cell styles.
20+
21+
```csharp
22+
using (ExcelEngine excelEngine = new ExcelEngine())
23+
{
24+
IApplication application = excelEngine.Excel;
25+
application.DefaultVersion = ExcelVersion.Xlsx;
26+
FileStream inputStream = new FileStream("Data/InputTemplate.xlsx", FileMode.Open, FileAccess.Read);
27+
IWorkbook workbook = application.Workbooks.Open(inputStream);
28+
IWorksheet worksheet = workbook.Worksheets[0];
29+
30+
// Remove first hyperlink without affecting cell styles
31+
HyperLinksCollection hyperlink = worksheet.HyperLinks as HyperLinksCollection;
32+
hyperlink.Remove(hyperlink[0] as HyperLinkImpl);
33+
34+
//Saving the workbook as stream
35+
FileStream outputStream = new FileStream("Output/Output.xlsx", FileMode.Create, FileAccess.Write);
36+
workbook.SaveAs(outputStream);
37+
workbook.Close();
38+
excelEngine.Dispose();
39+
}
40+
```
41+

0 commit comments

Comments
 (0)