Skip to content

Commit 699b151

Browse files
951831-DeleteHyperlinksXlsioExample
1 parent 789df97 commit 699b151

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed
Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,41 @@
11
# How to delete hyperlinks from worksheet without affecting the cell styles?
2-
Step 1: Create a new C# Console Application project.
32

4-
Step 2: Name the project.
3+
Step 1: Create a New C# Console Application Project.
4+
5+
Step 2: Name the Project.
56

67
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).
78

89
Step 4: Include the following namespaces in the **Program.cs** file.
9-
{% tabs %}
10-
{% highlight c# tabtitle="C#" %}
10+
11+
```csharp
12+
using System;
1113
using System.IO;
1214
using Syncfusion.XlsIO;
13-
{% endhighlight %}
14-
{% endtabs %}
15+
using Syncfusion.XlsIO.Implementation;
16+
using Syncfusion.XlsIO.Implementation.Collections;
17+
```
1518

1619
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#" %}
20+
21+
```csharp
1922
using (ExcelEngine excelEngine = new ExcelEngine())
2023
{
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();
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();
3639
}
37-
{% endhighlight %}
38-
{% endtabs %}
40+
```
41+

0 commit comments

Comments
 (0)