Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions File-Formats-toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -1669,6 +1669,7 @@
<li><a href="/file-formats/xlsio/faqs/how-to-vary-colors-by-point-for-line-and-column-chart">How to vary colors by point for line and column chart</a></li>
<li><a href="/file-formats/xlsio/faqs/how-to-upload-a-file-to-azure-blob-and-download-as-stream">How to upload a file to Azure blob and download as stream</a></li>
<li><a href="/file-formats/xlsio/faqs/how-to-set-rounded-corner-for-chart-in-excel-document">How to set rounded corner for chart in Excel document</a></li>
<li><a href="/file-formats/xlsio/faqs/how-to-find-and-replace-text-in-hyperlinks">How to find and replace text in hyperlinks</a></li>
</ul>
</li>
</ul>
Expand Down
3 changes: 2 additions & 1 deletion File-Formats/XlsIO/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,5 @@ The frequently asked questions in Essential XlsIO are listed below.
* [How to change the shape text font?](faqs/how-to-change-the-shape-text-font)
* [Why cone chart shows itself as column or bar chart?](faqs/why-cone-chart-shows-itself-as-colum-or-bar-chart)
* [How to vary colors by point for line and column chart?](faqs/how-to-vary-colors-by-point-for-line-and-column-chart)
* [How to upload a file to Azure blob and download as stream?](faqs/how-to-upload-a-file-to-azure-blob-and-download-as-stream)
* [How to upload a file to Azure blob and download as stream?](faqs/how-to-upload-a-file-to-azure-blob-and-download-as-stream)
* [How to find and replace text in hyperlinks](faqs/how-to-find-and-replace-text-in-hyperlinks)
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
title: Find and Replace text in Hyperlinks | Syncfusion
description: This page shows how to find and replace text in hyperlinks using the Syncfusion .NET Excel library (XlsIO).
platform: file-formats
control: XlsIO
documentation: UG
---

# How to find and replace text in hyperlinks?

The following code illustrates how to find and replace text in hyperlinks.

{% tabs %}
{% highlight c# tabtitle="C# [Cross-platform]" %}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;

//Loads an existing file.
FileStream inputstream = new FileStream("InputTemplate.xlsx", FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(inputstream);
IWorksheet sheet = workbook.Worksheets[0];

//Find and Replace text in hyperlinks
for (int i = 0; i < sheet.HyperLinks.Count; i++)
{
IHyperLink hyperLink = sheet.HyperLinks[i];
string address = hyperLink.Address;
string displayText = hyperLink.TextToDisplay;
hyperLink.Address = address.Replace("http://", "https://");
if (!string.IsNullOrEmpty(displayText))
hyperLink.TextToDisplay = displayText.Replace("http://", "https://");
}

// Saving the workbook
FileStream outputstream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.ReadWrite);
workbook.SaveAs(outputstream);
outputstream.Dispose();
}
{% endhighlight %}

{% highlight c# tabtitle="C# [Windows-specific]" %}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;

//Loads an existing file.
IWorkbook workbook = application.Workbooks.Open("InputTemplate.xlsx");
IWorksheet sheet = workbook.Worksheets[0];

//Find and Replace text in hyperlinks
for (int i = 0; i < sheet.HyperLinks.Count; i++)
{
IHyperLink hyperLink = sheet.HyperLinks[i];
string address = hyperLink.Address;
string displayText = hyperLink.TextToDisplay;
hyperLink.Address = address.Replace("http://", "https://");
if (!string.IsNullOrEmpty(displayText))
hyperLink.TextToDisplay = displayText.Replace("http://", "https://");
}

// Saving the workbook
workbook.SaveAs("Output1.xlsx");
}
{% endhighlight %}

{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
Using excelEngine As ExcelEngine = New ExcelEngine()
Dim application As IApplication = excelEngine.Excel
application.DefaultVersion = ExcelVersion.Xlsx

'Loads an existing file.
Dim workbook As IWorkbook = application.Workbooks.Open("InputTemplate.xlsx")
Dim sheet As IWorksheet = workbook.Worksheets(0)

'Find and Replace text in hyperlinks
For i As Integer = 0 To sheet.HyperLinks.Count - 1
Dim hyperLink As IHyperLink = sheet.HyperLinks(i)
Dim address As String = hyperLink.Address
Dim displayText As String = hyperLink.TextToDisplay
hyperLink.Address = address.Replace("http://", "https://")
If Not String.IsNullOrEmpty(displayText) Then
hyperLink.TextToDisplay = displayText.Replace("http://", "https://")
End If
Next

'Saving the workbook
workbook.SaveAs("Output.xlsx")
End Using
{% endhighlight %}
{% endtabs %}