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

I am exporting asp.net grid data to excel. But I am not sure about setting password for that, Can anyone give an idea about this ., here is my code..

Protected Sub btnPayroll_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPayroll.Click
Response.Clear()
Response.AddHeader("content-disposition", "attachment; filename=Monthly Payroll.xls")
Response.Charset = ""
Response.ContentType = "application/vnd.xls"
Dim stringWrite As New System.IO.StringWriter()
Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite)

Dim FilePathName As String = Request.PhysicalPath
Dim fileInfo = New IO.FileInfo(FilePathName)
fileInfo.IsReadOnly = True

GridView1.HeaderRow.Style.Add("background-color", "#99CCFF")


GridView1.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString())
Response.[End]()
End Sub
Posted

1 solution

Hi member, see this link[^]

and this [^]

if the above solutions does not helps you, please post your query here.

Thanks
Ganesh
 
Share this answer
 
Comments
Member 9861478 27-Sep-13 1:50am    
Hi Ganesh. My senario is different already tried those before. I am able to export to excel successfully. I am looking for Password protected for the excel after exporting to excel.
Here is my code.

Protected Sub btnPayroll_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPayroll.Click
Response.Clear()
Response.AddHeader("content-disposition", "attachment; filename=Monthly Payroll.xls")
Response.Charset = ""
Response.ContentType = "application/vnd.xls"
Dim stringWrite As New System.IO.StringWriter()
Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite)

Dim FilePathName As String = Request.PhysicalPath
Dim fileInfo = New IO.FileInfo(FilePathName)
fileInfo.IsReadOnly = True

GridView1.HeaderRow.Style.Add("background-color", "#99CCFF")


GridView1.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString())
Response.[End]()
End Sub

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