Excel export of datagrid is changing a value...

When I use the following function to export the contents of a datagrid to excel, the results are changed when I open the excel document.

For example the field with value '09-4720' will display as 'Sep-20'...  It's doing an auto convert somewhere in the process.

Any ideas of how to keep this change from happening?

Thanks,

Here is the function I'm using to export the data:


    Private Sub Imagebutton4_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles Imagebutton4.Click
       
            Dim SE As String
            SE = Session("SortExpression")
            dgdInv.AllowPaging = False
            dgdInv.AllowSorting = False
            BindData(SE)
            Dim stringWrite As New System.IO.StringWriter
            Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
            Dim w As System.Web.UI.WebControls.Unit
            w.Pixel(400)
            dgdInv.Width = w
            Dim scr As String = "<script>function window.onafterprint(){history.back(1);}</script>"
            htmlWrite.Write(scr)
            dgdInv.RenderControl(htmlWrite)
            Dim strHTML As String = stringWrite.ToString()
            Response.Clear()

            ' send to Excel
            Response.AddHeader("Content-Disposition", "attachment;filename=BurdenData.xls")
            Response.ContentType = "application/vnd.ms-excel"
            ' send to Printer
            'Response.ContentType = "text/HTML"

            Response.Write(strHTML)
            Response.Write("<script>window.print();</script>")
            Response.End()

       
    End Sub
Weller0123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

boulder_bumCommented:
You'd have to change the cell formatting, which I believe you'd have to do with the COM API for Excel (which can still be delivered via ASP.NET).

Awesome article to get you started:

http://www.aspnetpro.com/NewsletterArticle/2003/09/asp200309so_l/asp200309so_l.asp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mmarinovCommented:
Hi Weller0123,

there is no chaning the value through the export. the changing is in the excel when you open it, because the formatting of the cell is General by default and excel tryes to find the format of the cell itself
one way is to manually convert the all column cells to text formatting: select the complete column right click ->Format Cell->from the list select Text
other way, if you want to read the excel file programatically, and there you see the conversion, you have to change the value of this key in the registry
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Excel\TypeGuessRows
in this key is saved a number of rows that jet engine has to move through to understand what is the type of the hole column
so if your first column is text you can set it to 1 and it will return the correct values

Regards!
B..M
mmarinov
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.