Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,

I want to export excel on read only mode.User should not edit the Excel sheet. Please help. Export is working but not Read only property.

VB
Protected Sub btnExport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExport.Click
       Response.Clear()
       Response.AddHeader("content-disposition", "attachment; filename=ABC.xls")
       Response.Charset = ""
       Response.ContentType = "application/vnd.xls"

       Dim FilePathName As String = Request.PhysicalPath
       Response.WriteFile(FilePathName, IO.FileMode.Open, IO.FileAccess.Read)
       Dim stringWrite As New System.IO.StringWriter()
       Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite)

       GridView1.HeaderRow.Style.Add("background-color", "#99CCFF")
       GridView1.RenderControl(htmlWrite)
       Response.Write(stringWrite.ToString())

       Response.[End]()
Posted
Comments
Bernhard Hiller 19-Sep-13 2:29am    
Are you really sure that that works? I cannot imagine that. Or did you only try on your local machine - having both browser and IIS running locally? And your next question is: "... workking on my machine, but no working when deploy on server"?
Member 9861478 19-Sep-13 2:37am    
Thank you for the answer. I am working on my local machine not yet in server when I posted. I just now checked in Server. Is there any property to apply Readonly to excel?

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