Click here to Skip to main content
15,890,670 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
 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
C#
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

1 solution

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:
C#
sheet.Range["B5"].ClearAll();


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


You can see details:
Remove Excel Hyperlink[^]
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900