Skip to content

Commit 789df97

Browse files
951831-DeleteHyperlinksXlsioExample
1 parent 34c62b8 commit 789df97

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

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

Whitespace-only changes.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# How to delete hyperlinks from worksheet without affecting the cell styles?
2+
Step 1: Create a new C# Console Application project.
3+
4+
Step 2: Name the project.
5+
6+
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).
7+
8+
Step 4: Include the following namespaces in the **Program.cs** file.
9+
{% tabs %}
10+
{% highlight c# tabtitle="C#" %}
11+
using System.IO;
12+
using Syncfusion.XlsIO;
13+
{% endhighlight %}
14+
{% endtabs %}
15+
16+
Step 5: Include the below code snippet in **Program.cs** to delete hyperlinks from worksheet without affecting the cell styles.
17+
{% tabs %}
18+
{% highlight c# tabtitle="C#" %}
19+
using (ExcelEngine excelEngine = new ExcelEngine())
20+
{
21+
IApplication application = excelEngine.Excel;
22+
application.DefaultVersion = ExcelVersion.Xlsx;
23+
FileStream inputStream = new FileStream("Data/InputTemplate.xlsx", FileMode.Open, FileAccess.Read);
24+
IWorkbook workbook = application.Workbooks.Open(inputStream);
25+
IWorksheet worksheet = workbook.Worksheets[0];
26+
27+
// Remove first hyperlink without affecting cell styles
28+
HyperLinksCollection hyperlink = worksheet.HyperLinks as HyperLinksCollection;
29+
hyperlink.Remove(hyperlink[0] as HyperLinkImpl);
30+
31+
//Saving the workbook as stream
32+
FileStream outputStream = new FileStream("Output/Output.xlsx", FileMode.Create, FileAccess.Write);
33+
workbook.SaveAs(outputStream);
34+
workbook.Close();
35+
excelEngine.Dispose();
36+
}
37+
{% endhighlight %}
38+
{% endtabs %}

0 commit comments

Comments
 (0)