Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello,Everyone
I am working on web application .I have Exported gridview data in excel .but now i want add hyperlink to excel file before exporting.i.e when i get excel file the i should have hyperlink in excel and when user hit this link then directories open automatically.

What I have tried:

Response.Clear();
           Response.AddHeader("content-disposition", "attachment;filename=ExportData1.xls");
           Response.Charset = "";
           Response.ContentType = "application/vnd.xls";
           StringWriter StringWriter = new System.IO.StringWriter();
           HtmlTextWriter HtmlTextWriter = new HtmlTextWriter(StringWriter);

             gvDetails.RenderControl(HtmlTextWriter);

           Response.Write(StringWriter.ToString());
           Response.End();


the above code for export gridview data to excel.
I.e gridviews have id,filename,contenttype,and data type as columns.
I have to export all these field except data and additionaly add hyperlink to hit the file location on excel file.
the excel will be look like as...

Id	 FileName	          FileType	  DownLoad
56	Sujata_PDF.pdf	        application/PDF	Download
57	irctcticket.pdf	        application/PDF	Download
46	PBILLJG0050715-16.pdf	application/PDF	Download
47	PBILLJG0051215-16.pdf	application/PDF	Download
48	PBILLJG0051315-16.pdf	application/PDF	Download
49	PNSJG200001715-16.pdf	application/PDF	Download
50	purchase request.pdf	application/PDF	Download
51	SujataMadam.pdf	        application/PDF	Download
52	frmMatPDFPreview.pdf	application/PDF	Download
53	G3 Motors Ltd.pdf	application/PDF	Download
54	parsan Overseas Pvt Ltd (1).pdf	application/PDF	Download
55	parsan Overseas Pvt Ltd.pdf	application/PDF	Download
58	irctcticket2.pdf       application/PDF	Download
60	Hacking.pdf	       application/PDF	Download
Posted
Updated 16-Feb-17 7:22am
v2
Comments
SujataJK 8-Feb-17 0:36am    
Please give mi solution for above post..
SujataJK 9-Feb-17 23:46pm    
Ye..i got solution

1 solution

The problem is that you're not exporting an Excel sheet. You're exporting an HTML document, and asking the browser to open it in Excel.

Excel will then try to convert the HTML to an Excel sheet, but you have very little control over the result.

Instead, you should use a tool which will let you export a real Excel sheet. For example:
 
Share this answer
 

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