|
1 | 1 | # How to delete hyperlinks from worksheet without affecting the cell styles? |
2 | | -Step 1: Create a new C# Console Application project. |
3 | 2 |
|
4 | | -Step 2: Name the project. |
| 3 | +Step 1: Create a New C# Console Application Project. |
| 4 | + |
| 5 | +Step 2: Name the Project. |
5 | 6 |
|
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). |
7 | 8 |
|
8 | 9 | Step 4: Include the following namespaces in the **Program.cs** file. |
9 | | -{% tabs %} |
10 | | -{% highlight c# tabtitle="C#" %} |
| 10 | + |
| 11 | +```csharp |
| 12 | +using System; |
11 | 13 | using System.IO; |
12 | 14 | using Syncfusion.XlsIO; |
13 | | -{% endhighlight %} |
14 | | -{% endtabs %} |
| 15 | +using Syncfusion.XlsIO.Implementation; |
| 16 | +using Syncfusion.XlsIO.Implementation.Collections; |
| 17 | +``` |
15 | 18 |
|
16 | 19 | 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 |
19 | 22 | using (ExcelEngine excelEngine = new ExcelEngine()) |
20 | 23 | { |
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(); |
36 | 39 | } |
37 | | -{% endhighlight %} |
38 | | -{% endtabs %} |
| 40 | +``` |
| 41 | + |
0 commit comments