Click here to Skip to main content
11,577,522 members (45,927 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
Hello ALl,


I have save Report in Excel and after that when i Open Excel file that time all hyperlink I have to remove Because its asking for Credintials.


So please suggest me how to Remove HyperLink from Excel file which is read from Disk.

I just save report using below Code:
 string FilterFileName = (reportBll.GetFilterID() + 1).ToString() + "_" + pageTitle + "_" + System.DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss").Replace("/", "").Replace(" ", "").Replace(":", "") + ".xls";
                    string Folderpath = "";
                 
 Warning[] warnings;
 string[] streamids;
 string mimeType;
 string encoding;
 string extension;
byte[] bytes = rptViewer.ServerReport.Render("Excel", null, out mimeType, out encoding,out extension,out streamids, out warnings);         
 FileStream fs = new FileStream(reportBll.FileCopyLocation(out Folderpath)+ "\\" +  FilterFileName, FileMode.Create);
 fs.Write(bytes, 0, bytes.Length);
 fs.Close();

Below Code is for Open Excel File which is Save on Disk
string path = Config.Get("SaveFilterReport") + e.CommandArgument.ToString();
                    if (File.Exists(path))
                    {
                        Response.Buffer = true;
                        Response.Clear();
                        Response.ClearContent();
                        Response.Charset = "";
                        Response.AppendHeader("content-disposition", "attachment; filename=\"" + e.CommandArgument.ToString().Remove(0, e.CommandArgument.ToString().LastIndexOf("\\")).Remove(0, e.CommandArgument.ToString().IndexOf("_")) + "\"");
                        if (path.Contains(".xlsx"))
                          Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                        else
                          Response.ContentType = "application/vnd.ms-excel";
                        Response.TransmitFile(path);
                        Response.Flush();
                        Response.Close();
                        Response.End();
                    }

So I want to Remove Hyperlink from that Excel File.
suggest me what i do.
Posted 11-Nov-12 18:34pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

There are two hyperlinks, one is only hyperlink without text,the other is the hyperlink with text in cell called anchor text, both of them can take you automatically to the target place.
if you want to remove all including hyperlink and cell text, you can use:
sheet.Range["B5"].ClearAll();

for the second case, you can remove hyperlink effect and keep the cell text content,see below code:
sheet.HyperLinks.RemoveAt(0);

You can see details:
Remove Excel Hyperlink[^]
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 DamithSL 180
1 OriginalGriff 115
2 Richard MacCutchan 100
3 Abhinav S 90
4 Sergey Alexandrovich Kryukov 81
0 OriginalGriff 820
1 Sergey Alexandrovich Kryukov 681
2 Abhinav S 528
3 F-ES Sitecore 420
4 Suvendu Shekhar Giri 375


Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 12 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100