Last post Oct 25, 2018 09:38 AM by mnmhemaj
Oct 24, 2018 02:31 PM|mnmhemaj|LINK
I am using the following snippet to save a gridview data to an Excel file:
Using sw As New StringWriter()
Using hw As New HtmlTextWriter(sw)
Dim writer As StreamWriter = File.AppendText(fnamepath & fname)
There are some strange characters, like Â are found in the excel file. How can I save the data without these characters?
Oct 25, 2018 05:18 AM|Ackerly Xu|LINK
You should use corresponding encoding.
Private Sub Excel_Export()
Response.Buffer = True
Response.Charset = "UTF-8"
Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8")
Response.AppendHeader("content-disposition", "attachment;filename=""" & System.Web.HttpUtility.UrlEncode("your file name", System.Text.Encoding.UTF8) & ".xls""")
Response.ContentType = "Application/ms-excel"
Dim oStringWriter As System.IO.StringWriter = New System.IO.StringWriter()
Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter)
If it doesn't work, please open your excel with notepad and save it as utf8
Oct 25, 2018 06:46 AM|mnmhemaj|LINK
Hi! I am not opening an excel file. I am saving gridview data directly to an excel file. So I cannot use Response.xxx.
Oct 25, 2018 09:28 AM|Ackerly Xu|LINK
I am not understand what you have said clearly.
Because you could use gridview, I think you could use Response also.
My code is not opening an excel , my code is for downloading an excel with gridview data, it also save data to an excel file.
If you don't want to use response, as I have said, you could open your excel with notepad to see whether it is normal , if it is normal , please save it as UTF-8.
Oct 25, 2018 09:38 AM|mnmhemaj|LINK
I changed my code as
Dim writer As StreamWriter = New StreamWriter(fnamepath & fname, False, Encoding.UTF8)
now it works