From 88ba7a1298f7260d35e1db333b8edf672a08c11f Mon Sep 17 00:00:00 2001 From: KurmithaSF4004 Date: Mon, 5 Feb 2024 22:36:41 +0530 Subject: [PATCH 1/2] 868252-Hyperlinks-FAQ --- File-Formats/XlsIO/FAQ.md | 3 +- ...-to-find-and-replace-text-in-hyperlinks.md | 93 +++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 File-Formats/XlsIO/faqs/how-to-find-and-replace-text-in-hyperlinks.md diff --git a/File-Formats/XlsIO/FAQ.md b/File-Formats/XlsIO/FAQ.md index a559d3864..1ae4bb5a4 100644 --- a/File-Formats/XlsIO/FAQ.md +++ b/File-Formats/XlsIO/FAQ.md @@ -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) \ No newline at end of file +* [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) \ No newline at end of file diff --git a/File-Formats/XlsIO/faqs/how-to-find-and-replace-text-in-hyperlinks.md b/File-Formats/XlsIO/faqs/how-to-find-and-replace-text-in-hyperlinks.md new file mode 100644 index 000000000..bf0f9aa77 --- /dev/null +++ b/File-Formats/XlsIO/faqs/how-to-find-and-replace-text-in-hyperlinks.md @@ -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 %} \ No newline at end of file From 7f2e32e0ccf27c6edd8ffa4638da55f16efd0f5a Mon Sep 17 00:00:00 2001 From: KurmithaSF4004 Date: Mon, 5 Feb 2024 22:45:28 +0530 Subject: [PATCH 2/2] 868252-Hyperlinks-FAQ-Add file path --- File-Formats-toc.html | 1 + 1 file changed, 1 insertion(+) diff --git a/File-Formats-toc.html b/File-Formats-toc.html index 088baa45a..21e48d0bc 100644 --- a/File-Formats-toc.html +++ b/File-Formats-toc.html @@ -1669,6 +1669,7 @@
  • How to vary colors by point for line and column chart
  • How to upload a file to Azure blob and download as stream
  • How to set rounded corner for chart in Excel document
  • +
  • How to find and replace text in hyperlinks